dssnh86244 2019-06-24 02:14 采纳率: 100%
浏览 2271
已采纳

求助:即使设置环境路径也找不到GOPATH

用 linux 上安装好的 root 用户,在~/.zshrc文件中设置Go路径:

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
$ ls $HOME/go
bin pkg src

$ ls $HOME/go/bin
asmfmt  dlv  errcheck  fillstruct  gocode  gocode-gomod  godef  gogetdoc  goimports  golint  gometalinter  gomodifytags  gorename  gotags  gounit  guru  iferr  impl  keyify  motion

但是go env却返回如下信息:

zsh: command not found: go

为什么会这样?


附加内容

$ whereis go
go: /usr/local/go

将/usr/local设置为~/.zshrc:

export PATH=$PATH:/usr/local/

运行Go env会返回:

zsh: permission denied: go
  • 写回答

1条回答 默认 最新

  • duanqin9631 2019-06-24 04:21
    关注

    As commented, your ~/.zshrc should set PATH to reference Go, as seen in the Go wiki:

    Edit your ~/.zshrc file to add the following line:

    export GOPATH=$HOME/go
    

    Save and exit your editor. Then, source your ~/.zshrc.

    source ~/.zshrc
    

    As explained in the default GOPATH and issue 17262, you don't need to set GOPATH.

    But since Go 1.11 and its modules, you can now makes entire projects without ever using the default GOPATH at all: everything would remain local to your project.

    As of Go 1.11, the go command enables the use of modules when the current directory or any parent directory has a go.mod, provided the directory is outside $GOPATH/src.
    (Inside $GOPATH/src, for compatibility, the go command still runs in the old GOPATH mode, even if a go.mod is found)

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!