go get -> cannot download, /home/azhukov/go is a GOROOT, not a GOPATH

ぃ、小莉子 提交于 2020-11-29 05:23:52

问题


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:


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:


For mac,

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

  2. then run the go get -u [url]



来源:https://stackoverflow.com/questions/42809990/go-get-cannot-download-home-azhukov-go-is-a-goroot-not-a-gopath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!