英文:
go get -> cannot download, /home/azhukov/go is a GOROOT, not a GOPATH
问题
你好!我正在尝试在Google Cloud上安装gb(用于Go语言的依赖管理工具)。我尝试使用go get
命令,但失败了:
azhukov@gce-machine:~$ go get -v github.com/constabulary/gb/...
package github.com/pkg/errors: cannot download, /home/azhukov/go is a GOROOT, not a GOPATH. For more details see: 'go help gopath'
这是我的环境变量:
azhukov@gce-machine:~$ echo $GOPATH, $GOROOT, $PATH
/home/azhukov/go, , /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin:/home/azhukov/go/bin
Go版本:
azhukov@gce-machine:~$ go version
go version go1.8 linux/amd64
Go环境变量:
azhukov@gce-machine:~$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/azhukov/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build477416510=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
对我来说,一切看起来都没问题,我不明白为什么go get
会返回这样的错误。这是不符合逻辑的。
英文:
Good day! I am trying to install gb (vendoring tool for go) in Google Cloud.
I try go get
and it fails:
azhukov@gce-machine:~$ go get -v github.com/constabulary/gb/...
package github.com/pkg/errors: cannot download, /home/azhukov/go is a GOROOT, not a GOPATH. For more details see: 'go help gopath'
here is env:
azhukov@gce-machine:~$ echo $GOPATH, $GOROOT, $PATH
/home/azhukov/go, , /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin:/home/azhukov/go/bin
go version:
azhukov@gce-machine:~$ go version
go version go1.8 linux/amd64
go env:
azhukov@gce-machine:~$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/azhukov/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build477416510=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
To me everything looks fine, I don't get why would go get return such error. It is counter-logical.
答案1
得分: 14
这个错误是由于go
工具在你的GOPATH中检测到了Go安装引起的。它并不是在告诉你你的GOPATH是_GOROOT_(那是另一条消息),它是在告诉你的GOPATH看起来像是一个_GOROOT_。
清空你的GOPATH并再次运行go get
将修复这个错误。
英文:
This error is caused by the go
tool detecting a Go installation in your GOPATH. It's not telling you that your GOPATH is the GOROOT (that's a different message), it's telling your GOPATH looks like a GOROOT.
Cleaning out your GOPATH and running go get
again will fix the error.
答案2
得分: -2
对于Mac电脑,
-
在终端中运行
export GOPATH=$HOME/go
-
然后运行
go get -u
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论