dssnh86244
dssnh86244
采纳率100%
2019-06-24 02:14

求助:即使设置环境路径也找不到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 duanqin9631 2年前

    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)

    点赞 评论 复制链接分享