dqef7931
2017-04-14 05:12
浏览 130
已采纳

-bash:设置:-g:设置GOPATH时无效的选项

When I set my GOPATH use:

set -gx GOPATH /usr/local/Cellar/go/1.8.1

I get this issue:

-bash: set: -g: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]

图片转代码服务由CSDN问答提供 功能建议

设置我的 GOPATH 时,请使用:

 设置-gx GOPATH /usr/local/Cellar/go/1.8.1
  
 
 

我遇到此问题:

-bash:设置:-g:无效选项
设置:用法:设置[--abefhkmnptuvxBCHP] [-o选项] [arg ...]

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongliang1873 2017-04-14 06:33
    已采纳

    The bash command set doesn't support the g option. Also this command is not used for setting environment variables all together - your snippet is probably intended for a different shell (fishshell?).

    In bash, use export as suggested:

    export GOPATH /usr/local/Cellar/go/1.8.1
    

    However, you should understand what you are doing and how to configure your environment on MacOS (guessing from 'Cellar' in your path).

    This might be a good starting point.

    点赞 打赏 评论
  • dp9599 2017-04-14 05:21

    You should set GOROOT environment variable instead of GOPATH.

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

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

    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.
    点赞 打赏 评论

相关推荐 更多相似问题