不能再执行任何 go 命令

Cannot do any go command anymore

在它发生之前,我正在做的是尝试使用 dep 来管理我的 golang 代码依赖。 我现在发现我无法使用 go 执行任何命令,即使我尝试使用 brew by brew uninstall go 和再做一次brew install go

如果我正在做 go env 它将显示如下:

$ go env
go: cannot find GOROOT directory: /usr/local/cellar/go/1.13.1/libexec

$ ls /usr/local/Cellar/go/1.13.8/libexec/
CONTRIBUTING.md SECURITY.md bin     lib     robots.txt
CONTRIBUTORS    VERSION     doc     misc        src
PATENTS     api     favicon.ico pkg     test

$ go version
go: cannot find GOROOT directory: /usr/local/cellar/go/1.13.1/libexec

$ go build
go: cannot find GOROOT directory: /usr/local/cellar/go/1.13.1/libexec

$ echo $GOPATH
/Users/mymac/go

$ echo $GOROOT

$

我应该做什么检查?

试试这个:

https://gist.github.com/vsouza/77e6b20520d07652ed7d

# Set variables in .bashrc file

# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin

当然,您需要将“$HOME/golang”和“/usr/local/opt/go: 更改为您的实际路径名。


来自 OP:

finally i solve this, can you help to update your comment then i will set it as SOLVED.

i use

export GOROOT=/usr/local/Cellar/go/1.13.8/libexec/

instead of

GOROOT=/usr/local/opt/go/libexec

我个人将其用于 Homebrew

export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
# Homebrew
export GOROOT="$(brew --prefix golang)/libexec"
# Manual install
# export GOROOT=/usr/local/go
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin