【问题标题】:Cannot do any go command anymore不能再执行任何 go 命令
【发布时间】:2020-02-26 04:23:18
【问题描述】:

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

$

我应该怎么做和检查?

【问题讨论】:

  • 不要通过 brew 安装 Go。使用来自 golang.org 的官方 Go 发行版。并且不要使用 dep。

标签: go command-line-interface homebrew godeps gopath


【解决方案1】:

我个人将它用于 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

【讨论】:

  • export GOROOT="$(brew --prefix golang)/libexec" 拯救了我的一天。
  • 完美运行。谢谢。
【解决方案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:

我终于解决了这个问题,你能帮忙更新你的评论然后我会的 将其设置为已解决。

我用

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

而不是

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

【讨论】:

  • 好吧,我不认为 GOPATH 应该指向 GO 二进制路径。 GOPATH 是可维护的酸性源代码所在的位置。
  • 很公平。查看我修改后的 cmets
  • 我终于解决了这个问题,你能帮忙更新你的评论吗?我使用 export GOROOT=/usr/local/Cellar/go/1.13.8/libexec/ 而不是 GOROOT=/usr/local/opt/go/libexec 然后我将其设置为 SOLVED。
猜你喜欢
  • 1970-01-01
  • 2014-01-23
  • 2019-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多