Reputation: 2031
$ 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?
Upvotes: 3
Views: 8637
Reputation: 1326994
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 pathsudo -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.
Upvotes: 9
Reputation: 1232
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.
Upvotes: 1