英文:
Go ignores exported GOPATH
问题
我按照Linux的Go安装说明进行操作,运行了sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
命令,并将/usr/local/go/bin
添加到了$PATH
中。不幸的是,我遇到了问题,因为在终端中go
忽略了对$GOPATH
的任何导出尝试。发生了什么问题,我该如何解决?
$ export GOPATH=$HOME/Go
$ echo $GOPATH
/home/rsg/Go
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build834345994=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
编辑:经过进一步检查,似乎由于某种原因,我无法导出GOPATH。我不确定原因,因为导出其他变量(例如FOO)完全正常。到底发生了什么?
rsg@P ~ $ env | grep FOO
rsg@P ~ $ env | grep GOPATH
rsg@P ~ $ export FOO=bar
rsg@P ~ $ env | grep FOO
FOO=bar
rsg@P ~ $ export GOPATH=bar
rsg@P ~ $ env | grep GOPATH
rsg@P ~ $ GOPATH=foo env | grep GOPATH
GOPATH=foo
rsg@P ~ $ env | grep GOPATH
英文:
I followed the linux go installation instructions and ran sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
and added /usr/local/go/bin
to $PATH
. Unfortunately, I am stuck because go
ignores any attempt to export $GOPATH
in the terminal. What's going on and how can I fix it?
$ export GOPATH=$HOME/Go
$ echo $GOPATH
/home/rsg/Go
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build834345994=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
Edit: On further inspection, it seems that for some reason, I am unable to export GOPATH at all. I am not sure why, because exporting other variables (e.g. FOO) works just fine. What on earth is going on?
rsg@P ~ $ env | grep FOO
rsg@P ~ $ env | grep GOPATH
rsg@P ~ $ export FOO=bar
rsg@P ~ $ env | grep FOO
FOO=bar
rsg@P ~ $ export GOPATH=bar
rsg@P ~ $ env | grep GOPATH
rsg@P ~ $ GOPATH=foo env | grep GOPATH
GOPATH=foo
rsg@P ~ $ env | grep GOPATH
答案1
得分: 0
我仍然不知道问题是什么,但运行unset GOPATH
解决了它。
英文:
I still have no idea what the problem was, but running unset GOPATH
fixed it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论