How to set GOPATH in Mac OS X 10.10

随声附和 提交于 2019-12-02 21:03:35
VonC

Notes:

GOROOT should reference a folder (where go is installed), not the go executable itself

export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin 

As Dave mentions in the comments, you should not have to set GOROOT at all in your case.
See the article You don’t need to set GOROOT, really.

GOPATH should reference a folder under which you will find src, pkg and bin. (it should not reference directly the src folder):
See "How to Write Go Code - Workspace"

Regarding the GOPATH:

  • try and set it in your ~/.bashrc (using export).
  • check that your current shell is a bash (and not another one like fish)
  • check the output of go env.

Don't do a sudo go get, as the environment variable used for sudo (root) wouldn't be the same as the current user:

go get github.com/gocql/gocql

(or you would need to do a sudo -E bash -c 'go get github.com/gocql/gocql', but I suspect you don't need root here)

See sudo caveat:

Any variables added to these locations will not be reflected when invoking them with a sudo command, as sudo has a default policy of resetting the Environment and setting a secure path (this behavior is defined in /etc/sudoers)

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