3

在它发生之前,我正在做的是尝试使用dep来管理我的golang代码依赖关系。我现在发现的是我无法使用go执行任何命令,即使我尝试使用brew by卸载它brew uninstall gobrew 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

$

我应该怎么做和检查?

4

2 回答 2

6

我个人将其用于 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
于 2021-05-10T07:37:54.127 回答
2

试试这个:

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:

最后我解决了这个问题,你能帮忙更新你的评论然后我将它设置为 SOLVED。

我用

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

代替

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

于 2020-02-26T04:29:24.573 回答