英文:
Why can't "go get" find $GOPATH when "go env" shows it's set correctly?
问题
我正在尝试在我的Macbook Pro上安装go版本go1.6.4 darwin/amd64。
尽管已经设置了$GOPATH,但我似乎无法使用'go get'下载远程包。
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Bryan/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
$ ls /Users/Bryan/go
total 24
drwxr-xr-x 6 Bryan staff 204 May 23 12:13 .
drwxr-xr-x+ 73 Bryan staff 2482 May 25 11:20 ..
-rw-r--r--@ 1 Bryan staff 8196 May 24 15:11 .DS_Store
drwxr-xr-x 32 Bryan staff 1088 Mar 28 14:21 bin
drwxr-xr-x 3 Bryan staff 102 Mar 28 14:21 pkg
drwxr-xr-x 10 Bryan staff 340 May 25 11:18 src
Bryan@Bryans-MacBook-Pro Thu May 25 12:23:24 ~/go/src/skincarereview
$ sudo go get
Password:
package google.golang.org/appengine: 无法下载,未设置$GOPATH。有关详细信息,请参阅:go help gopath
package google.golang.org/appengine/datastore: 无法下载,未设置$GOPATH。有关详细信息,请参阅:go help gopath
英文:
I'm attempting to get go version go1.6.4 darwin/amd64 installed on my Macbook Pro.
I can't seem to download remote packages with 'go get' despite having the $GOPATH set.
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Bryan/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
$ ls /Users/Bryan/go
total 24
drwxr-xr-x 6 Bryan staff 204 May 23 12:13 .
drwxr-xr-x+ 73 Bryan staff 2482 May 25 11:20 ..
-rw-r--r--@ 1 Bryan staff 8196 May 24 15:11 .DS_Store
drwxr-xr-x 32 Bryan staff 1088 Mar 28 14:21 bin
drwxr-xr-x 3 Bryan staff 102 Mar 28 14:21 pkg
drwxr-xr-x 10 Bryan staff 340 May 25 11:18 src
Bryan@Bryans-MacBook-Pro Thu May 25 12:23:24 ~/go/src/skincarereview
$ sudo go get
Password:
package google.golang.org/appengine: cannot download, $GOPATH not set. For more details see: go help gopath
package google.golang.org/appengine/datastore: cannot download, $GOPATH not set. For more details see: go help gopath
答案1
得分: 4
你的$GOPATH
设置在你的用户$PATH
中,但是你正在使用sudo
来调用go get
,而sudo
有自己独立的$PATH
。
为了说明这一点,尝试运行sudo go env
,你会看到它们之间的差异。
不过,你可能本来就不应该使用sudo go get
。
英文:
Your $GOPATH
is set in your user $PATH
, but you are envoking go get
using sudo
which has its own $PATH
different from yours.
To illustrate, try sudo go env
and you will see the difference.
You probably shouldn't be using sudo go get
anyway though.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论