Installing some go packages fails with permission denied
error, eg.:
$ go get code.google.com/p/go.tools/cmd/cover
go install code.google.com/p/go.tools/cmd/cover: open /usr/local/go/pkg/tool/darwin_amd64/cover: permission denied
When I tried using sudo
to fix the permission issue, it failed with $GOPATH not set
error:
$ sudo go get code.google.com/p/go.tools/cmd/cover
Password:
package code.google.com/p/go.tools/cmd/cover: cannot download, $GOPATH not set. For more details see: go help gopath
How can I solve this?
The godoc
, go tool vet
, go tool cover
etc. are special go.tools commands that are meant to be installed into the system path by default with the go binary. If these commands are not available, you should try reinstall go itself (or find go.tools
in your packaging system).
Note: On OS X 10.8+, try installing go using Homebrew instead of the official .pkg installer and your troubles should be gone (as of go 1.4): brew install go
If you want to download a specific pkg into your $GOPATH
(eg. 3rd party dependency), use go get -d <pkg>
instead. Example:
go get -d code.google.com/p/go.tools/cmd/cover
You shouldn't need to use the sudo
hammer at all, as your $GOPATH
should point to a directory that you own, and thus no permission: denied
error at all.
But if you really know what you're doing, and you still want to sudo
install something, you need to edit the sudoers file first to fix the root's GOPATH:
$ sudo visudo
add the following line:
Defaults env_keep += "GOPATH"
This will make the sudo go get
(root context) pick up your $GOPATH
value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With