在它发生之前,我正在做的是尝试使用 dep 来管理我的 golang 代码依赖项。
我现在发现我无法使用 go 执行任何命令,即使我尝试使用 brew uninstall go
的
brew卸载它并再次执行
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
$
我应该做什么和检查?
我个人用它来自制
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
试试这个:
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:
终于我解决了这个问题,你能帮忙更新你的评论吗,然后我会 将其设置为已解决。
我用
export GOROOT=/usr/local/Cellar/go/1.13.8/libexec/
而不是
GOROOT=/usr/local/opt/go/libexec
我使用自制程序安装Go版本。 1.20,以及上面的解决方案对我来说只需一些小调整即可工作。
而不是这个:
export GOROOT=/usr/local/opt/go/libexec
我必须使用这个:
export GOROOT=/opt/homebrew/opt/[email protected]/libexec
基本上使用以下命令在本地搜索 libexec 文件夹:
which libexec
然后使用这个路径来设置GOROOT。