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条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料