Go忽略了导出的GOPATH。

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

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的任何导出尝试。发生了什么问题,我该如何解决?

  1. $ export GOPATH=$HOME/Go
  2. $ echo $GOPATH
  3. /home/rsg/Go
  4. $ go env
  5. GOARCH="amd64"
  6. GOBIN=""
  7. GOEXE=""
  8. GOHOSTARCH="amd64"
  9. GOHOSTOS="linux"
  10. GOOS="linux"
  11. GOPATH=""
  12. GORACE=""
  13. GOROOT="/usr/local/go"
  14. GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
  15. CC="gcc"
  16. GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build834345994=/tmp/go-build -gno-record-gcc-switches"
  17. CXX="g++"
  18. CGO_ENABLED="1"

编辑:经过进一步检查,似乎由于某种原因,我无法导出GOPATH。我不确定原因,因为导出其他变量(例如FOO)完全正常。到底发生了什么?

  1. rsg@P ~ $ env | grep FOO
  2. rsg@P ~ $ env | grep GOPATH
  3. rsg@P ~ $ export FOO=bar
  4. rsg@P ~ $ env | grep FOO
  5. FOO=bar
  6. rsg@P ~ $ export GOPATH=bar
  7. rsg@P ~ $ env | grep GOPATH
  8. rsg@P ~ $ GOPATH=foo env | grep GOPATH
  9. GOPATH=foo
  10. 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/binto $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?

  1. $ export GOPATH=$HOME/Go
  2. $ echo $GOPATH
  3. /home/rsg/Go
  4. $ go env
  5. GOARCH="amd64"
  6. GOBIN=""
  7. GOEXE=""
  8. GOHOSTARCH="amd64"
  9. GOHOSTOS="linux"
  10. GOOS="linux"
  11. GOPATH=""
  12. GORACE=""
  13. GOROOT="/usr/local/go"
  14. GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
  15. CC="gcc"
  16. GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build834345994=/tmp/go-build -gno-record-gcc-switches"
  17. CXX="g++"
  18. 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?

  1. rsg@P ~ $ env | grep FOO
  2. rsg@P ~ $ env | grep GOPATH
  3. rsg@P ~ $ export FOO=bar
  4. rsg@P ~ $ env | grep FOO
  5. FOO=bar
  6. rsg@P ~ $ export GOPATH=bar
  7. rsg@P ~ $ env | grep GOPATH
  8. rsg@P ~ $ GOPATH=foo env | grep GOPATH
  9. GOPATH=foo
  10. rsg@P ~ $ env | grep GOPATH

答案1

得分: 0

我仍然不知道问题是什么,但运行unset GOPATH解决了它。

英文:

I still have no idea what the problem was, but running unset GOPATH fixed it.

huangapple
  • 本文由 发表于 2016年9月4日 05:13:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/39311386.html
匿名

发表评论

匿名网友

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

确定