duan198811 2015-02-26 11:47
浏览 59
已采纳

如何在Mac OS X 10.10中设置GOPATH

I installed Go 1.4 in Mac OS X. Previously I had Go 1.0. I set the GOROOT and PATH as follows,

Dineshs-MacBook-Air:go-cassandra Dany$ which go
/usr/local/go/bin/go
Dineshs-MacBook-Air:go-cassandra Dany$ export GOROOT=/usr/local/go/bin/go
Dineshs-MacBook-Air:go-cassandra Dany$ export PATH=$PATH:$GOROOT/bin 

Go is installed in '/usr/local/go/bin/go'. And I set the GOPATH as my project src directory. I am able to run go code inside my directory. But when I try to install gocql I am getting error.

Dineshs-MacBook-Air:go-cassandra Dany$ sudo go get github.com/gocql/gocql
package github.com/gocql/gocql: cannot download, $GOPATH not set. For more details see: go help gopath

Could anyone help me on this? Thank you

EDIT 1: @VonC I tried the other option as well. I changed the GOROOT to the directory where go is installed. But it didn't help. And I changed the GOPATH.

Dineshs-MacBook-Air:go-cassandra Dany$ export GOROOT=/usr/local/go
Dineshs-MacBook-Air:go-cassandra Dany$ export PATH=$PATH:$GOROOT/bin
Dineshs-MacBook-Air:go-cassandra Dany$ export GOPATH=/Users/Dany/Documents/FALL-2013-COURSES/Imp_Data_structures/workspace/go-cassandra
Dineshs-MacBook-Air:go-cassandra Dany$ sudo go get github.com/gocql/gocql
Password:
package github.com/gocql/gocql: cannot download, $GOPATH not set. For more details see: go help gopath
Dineshs-MacBook-Air:go-cassandra Dany$ echo $GOPATH
/Users/Dany/Documents/FALL-2013-COURSES/Imp_Data_structures/workspace/go-cassandra
Dineshs-MacBook-Air:go-cassandra Dany$ ls
bin pkg src
Dineshs-MacBook-Air:go-cassandra Dany$
  • 写回答

1条回答 默认 最新

  • dongmo8943 2015-02-26 11:51
    关注

    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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c