dongyang2229 2013-02-20 19:25
浏览 41
已采纳

在非默认目录中安装Go软件包

I've created an API in Go in which I've installed two packages via go get and have created four others for my own use. Everything seems to work fine. However I would like to move where the packages are so that I can have everything within my Git directory.

From what I've read, it should be as easy as changing my GOPATH variable to the new directory, and running go get again to test. Is this correct? If it is, am I doing anything wrong? Below is what shows in the terminal (Mac OS X) when I run go env. If any other info would be useful, please let me know. Thanks.

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Applications/MAMP/htdocs/git/cbi/api"
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CGO_ENABLED="1"

I should clarify that by default my GOPATH was an empty string. I tried updating it to the directory above since that is where I wish new packages be installed, and also for Go to look for any packages I've created an placed there.

I'm setting my GOPATH variable by running:

export GOPATH="/Applications/MAMP/htdocs/git/cbi/api"

After doing this, I can see the variable has been set when I type go env. However if I quit Terminal and then open it back up, and run go env again, the GOPATH variable is not set. Is there a reason it's not saving? Should I be setting it another way instead of export?

  • 写回答

3条回答 默认 最新

  • douou2026 2013-02-21 13:21
    关注

    If you don't set the GOPATH variable, the packages will be installed in the GOROOT which is not recommended. If you want to set GOPATH to "/Applications/MAMP/htdocs/git/cbi/api", make sure the directory of your code is put in "/Applications/MAMP/htdocs/git/cbi/api/src/".

    However if I quit Terminal and then open it back up, and run "go env" again, the GOPATH variable is not set.
    

    Like jeremy says, you should set the environment variable in bash configure file. In mac os, add this to your $HOME/.profile : export GOPATH=/Applications/MAMP/htdocs/git/cbi/api . BTW, you can specify multiple GOPATH, for exmple, export GOPATH=/path/to/gopath1:/path/to/gopath2

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能