无法再执行任何go命令

hm2xizp9  于 2023-03-10  发布在  Go
关注(0)|答案(2)|浏览(131)

在此之前,我正在尝试使用dep来管理我的golang代码依赖项。我现在发现我无法使用go执行任何命令,即使我尝试使用brewby 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

$

我应该怎么做和检查?

km0tfn4u

km0tfn4u1#

我个人用这个自制

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

Blogpost

ifsvaxew

ifsvaxew2#

试试这个:
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

相关问题