无法下载,/home/azhukov/go 是 GOROOT,而不是 GOPATH。

huangapple go评论85阅读模式
英文:

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电脑,

  1. 在终端中运行export GOPATH=$HOME/go

  2. 然后运行go get -u

英文:

For mac,

  1. run export GOPATH=$HOME/go in terminal

  2. then run the go get -u

huangapple
  • 本文由 发表于 2017年3月15日 20:37:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/42809990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定