2
$ sudo go get -u github.com/golang/lint/golint
package github.com/golang/lint/golint: cannot download, $GOPATH not set. For more details see: go help gopath

I have set my $GOPATH: (in ~/.bash_profile on my Mac) export GOPATH=$HOME/gocode

And my go env:

$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/wildcat/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fno-common"
CXX="g++"
CGO_ENABLED="1"

What's the problem?

PiotrWolkowski
  • 7,550
  • 5
  • 38
  • 58
WildCat
  • 1,673
  • 4
  • 22
  • 30

2 Answers2

8

The issue is that you are using sudo: it will use the root environment variable instead of the ones of your account.

You shouldn't need to use sudo, as I mentioned in "How to set GOPATH in Mac OS X 10.10":

  • sudo has a default policy of resetting the Environment and setting a secure path
  • unless you use the more complex sudo -E bash -c 'go get github.com/golang/lint/golint'):

For now, this should be enough:

go get -u github.com/golang/lint/golint

The OP adds a different go get command in the comments:

go install golang.org/x/tools/cmd/cover: 
  open /usr/local/go/pkg/tool/darwin_amd64/cover: permission denied 

That one would be using $GOTOOLDIR (set in your case to "/usr/local/go/pkg/tool/darwin_amd64")

As documented in "Permission denied error for 'go.tools'", running sudo -s then the go get command should work.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • `go install golang.org/x/tools/cmd/cover: open /usr/local/go/pkg/tool/darwin_amd64/cover: permission denied` How can I execute commands like this? – WildCat Mar 04 '15 at 15:10
  • @WildCat: `cmd/cover` is an exception to the rule. You can use sudo, or on osx I prefer to make my go installing writable by my local user account. – JimB Mar 04 '15 at 15:12
  • # go get -u github.com/golang/lint/golint ...... I ran this no error but still golint command not found – Ashish Karpe Jul 02 '18 at 07:34
  • 1
    @AshishKarpe Maybe because `$GOPATH/bin` is not in your `$PATH`? – VonC Jul 02 '18 at 07:50
1

sudo according to man:

sudo allows a permitted user to execute a command as the superuser or another user, as specified by the security policy.

When using sudo you are executing as root. I would suggest that you remove sudo and try executing it.

satran
  • 1,172
  • 4
  • 14
  • 27