Go install在zsh中无法正常工作。

huangapple go评论91阅读模式
英文:

Go install not working with zsh

问题

我感觉自己像个白痴,因为我之前在 macOS 和 OSX 上安装过这个,但出于某种原因,我看不出我做错了什么。请帮帮我!我创建了一个目录 ~/go,它将成为我的工作空间。当我从我的主目录运行 go env 时,我得到 zsh: command not found: go,我知道这是由于以下文件的原因。我的配置有什么问题吗?

~/.bash_profile:

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

~/.zshrc:

export PATH=$PATH:/usr/local/go/bin
英文:

I feel like an idiot because I've installed this before on macOS and OSX but for some reason I can't see what I'm doing wrong. Please help!!! I've created a directory, ~/go, which will be my workspace. When I run go env from my home directory I get zsh: command not found: go and I know it's because of the following files. What is wrong in my configuration?

~/.bash_profile:

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

~/.zshrc:

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

答案1

得分: 27

如果你在Mac OS上安装Go时不是使用Homebrew,而是使用macOS软件包安装程序,那么你的_GOBIN_将位于/usr/local/go,而_GOPATH_将位于$HOME/go,最后在~/.zshrc文件中添加以下内容:

  export GOPATH=$HOME/go
  export GOROOT=/usr/local/go
  export GOBIN=$GOPATH/bin
  export PATH=$PATH:$GOPATH
  export PATH=$PATH:$GOROOT/bin
英文:

If you installed on Mac OS not with home-brew but with the macOS package installer, your GOBIN be in /usr/local/go and GOPATH in $HOME/go, finally in ~/.zshrc:

  export GOPATH=$HOME/go
  export GOROOT=/usr/local/go
  export GOBIN=$GOPATH/bin
  export PATH=$PATH:$GOPATH
  export PATH=$PATH:$GOROOT/bin

答案2

得分: 20

以下配置对我有效,

~/.zshrc

export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH
export PATH=$PATH:$GOROOT/bin

然后你可以通过以下方式查看配置的详细信息

> go env

GOARCH="amd64"
GOBIN="/Users/my-name/golang/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/my-name/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6q/h6nchrdj49zgjfcp8wstj94r0000gn/T/go-build874871088=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
英文:

Below config is working for me,

in ~/.zshrc

export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH
export PATH=$PATH:$GOROOT/bin

You can see the configured details as below then

> go env

GOARCH="amd64"
GOBIN="/Users/my-name/golang/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/my-name/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6q/h6nchrdj49zgjfcp8wstj94r0000gn/T/go-build874871088=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

答案3

得分: 2

通过brew安装go并没有在shell配置文件中添加全局ENV路径。所以,我不得不手动像在~/.zshrc文件中添加如下内容,然后就可以了!

export PATH="$PATH:$(go env GOPATH)/bin"

注意:如果你使用的是bash或其他shell,配置文件的名称可能会有所不同!

英文:

Installing go through brew didn't add the global ENV path in the shell profile. So, I had to manually add it like in the ~/.zshrc file like the following and that was it!

export PATH="$PATH:$(go env GOPATH)/bin"

Note: If you are using bash or other shell, the name of the profile file would be different!

huangapple
  • 本文由 发表于 2017年3月6日 05:37:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/42614380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定