英文:
I have set my $GOPATH, but it doesn't work
问题
问题是无法下载github.com/golang/lint/golint
包,因为$GOPATH
未设置。根据错误信息,你可以尝试运行go help gopath
命令获取更多详细信息。
你已经在~/.bash_profile
文件中设置了$GOPATH
,路径为$HOME/gocode
。
你可以运行go env
命令来查看你的go
环境变量设置。根据输出,GOPATH
的值应该是/Users/wildcat/gocode
。
请检查你的环境变量设置是否正确,并确保$GOPATH
已正确设置。
英文:
$ 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?
答案1
得分: 9
问题在于你正在使用 sudo
:它将使用根环境变量而不是你的账户的环境变量。
你不应该使用 sudo
,就像我在“如何在Mac OS X 10.10中设置GOPATH”中提到的那样:
sudo
有一个默认策略,会重置环境并设置安全路径- 除非你使用更复杂的
sudo -E bash -c 'go get github.com/golang/lint/golint'
命令:
目前,这应该足够了:
go get -u github.com/golang/lint/golint
OP 在评论中添加了一个不同的 go get
命令:
go install golang.org/x/tools/cmd/cover:
open /usr/local/go/pkg/tool/darwin_amd64/cover: permission denied
这个命令将使用 $GOTOOLDIR
(在你的情况下设置为“/usr/local/go/pkg/tool/darwin_amd64”)
正如在“go.tools的权限被拒绝错误”中所述,运行 sudo -s
然后执行 go get
命令应该可以解决问题。
英文:
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.
答案2
得分: 1
根据man页面的说明:
sudo允许授权用户以超级用户或其他用户的身份执行命令,具体取决于安全策略。
当使用sudo
时,您是以root用户身份执行命令。我建议您删除sudo并尝试执行该命令。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论