[英]All of a sudden go tool: no such tool "compile"
I had installed go on my Ubuntu desktop and it worked fine before I switch off the computer.我已经在我的 Ubuntu 桌面上安装了 go,在我关闭计算机之前它运行良好。
Now as I started my machine and resumed my work on the project, I get this现在,当我启动我的机器并继续我的项目工作时,我得到了这个
$ go build
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
When I try to build a project.当我尝试构建一个项目时。
The only thing that I did before poweroff which might have some effect was to install godoc using我在 poweroff 之前做的唯一可能有一些影响的事情是使用安装 godoc
sudo apt-get install golang-doc
I had install go directly by downloading go1.10.1.linux-amd64.tar.gz
file, not using apt-get
我通过下载go1.10.1.linux-amd64.tar.gz
文件直接安装了 go,没有使用apt-get
go env go 环境
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/me/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/me/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build255010769=/tmp/go-build -gno-record-gcc-switches"
$ go version $ go 版本
go version go1.10.1 linux/amd64
I can still run comiled go code.我仍然可以运行编译的 go 代码。
What could have gone wrong here?这里可能出了什么问题? How can I fix it?我该如何解决?
The compile
program should be in your go env
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
directory. compile
程序应该在你的go env
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
目录中。 If not, download Go, delete /usr/local/go
, and reinstall Go.如果没有,请下载 Go,删除/usr/local/go
,然后重新安装 Go。
这可能看起来很奇怪,但运行export GOROOT=
为我解决了这个问题。
I have having a similar issues with MacOS Monterey (ARM Chip) when I run the go tour, the output says 'go tool no such tool 'compile''当我运行 go tour 时,我在 MacOS Monterey(ARM 芯片)上遇到了类似的问题,输出显示“go tool no such tool 'compile'”
I did notice that instead of the amd_64
file in usr/local/go/pkg/tool
I have this:我确实注意到,而不是usr/local/go/pkg/tool
中的amd_64
文件,我有这个:
/usr/local/go/pkg/tool/darwin_amd64
I tried changing the GOTOOLDIR variable, but I am still having the same issue:我尝试更改 GOTOOLDIR 变量,但仍然遇到相同的问题:
export GOTOOLDIR=/usr/local/go/pkg/tool/darwin_amd64
Downloading .tar.gz
versus using apt-get
may cause go env
values conflicts/overrides.下载.tar.gz
与使用apt-get
可能会导致go env
值冲突/覆盖。 Better to stick to one installation approach.最好坚持一种安装方法。
I had faced a similar problem in Mac.我在 Mac 中遇到过类似的问题。 When I installed Go using .dmg
(similar to your .tar.gz
case), it set a completely different value for GOTOOLDIR
, versus when I installed Go using brew install golang
(similar to your apt-get
case).当我使用.dmg
安装 Go 时(类似于您的.tar.gz
案例),它为GOTOOLDIR
设置了一个完全不同的值,而当我使用brew install golang
时(类似于您的apt-get
案例)。
Analysis:分析:
If you do the following:如果您执行以下操作:
go env | grep GOTOOLDIR
cd <value of GOTOOLDIR>
ls
You should see the following (notice the compile
binary):您应该看到以下内容(注意compile
二进制文件):
addr2line buildid cover fix objdump test2jsonapi
cgo dist link pack trace
asm compile doc nm pprof vet
If you don't, then you have probably switched to the wrong/overwritten/earlier Go installation.如果你不这样做,那么你可能已经切换到错误/覆盖/更早的 Go 安装。
Solution:解决方案:
After upgrading go
I started getting this error and updating GOROOT from /Users/bharkum3/.go
to /Users/bharkum3/.go/go-1.18.2
worked for me.升级go
后,我开始收到此错误并将 GOROOT 从/Users/bharkum3/.go
更新到/Users/bharkum3/.go/go-1.18.2
为我工作。
Looks like go install is creating a separate folder now for each versions (our script is doing this I guess) and need the above to redirect the compiler to the right version.看起来 go install 现在正在为每个版本创建一个单独的文件夹(我猜我们的脚本正在这样做)并且需要上面的内容将编译器重定向到正确的版本。
I was facing the same issue in my MAC M1.我在我的 MAC M1 中遇到了同样的问题。
Previously, I had downloaded it using "brew".以前,我使用“brew”下载了它。 I tried downloading it manually and reinstalling it.我尝试手动下载并重新安装。 That worked for me.这对我有用。
go version: 1.18.2 Download: https://go.dev/dl/ go 版本:1.18.2 下载: https://go.dev/dl/
I ran into a similar issue, but on a different system than op, windows+cygwin to be exact.我遇到了类似的问题,但在与 op 不同的系统上,确切地说是 windows+cygwin。
The issue for me was that the files inside the tools folder were not marked as executable.我的问题是工具文件夹中的文件未标记为可执行文件。
To solve this:要解决这个问题:
chmod a+x *
On Apple Silicon / M1.在 Apple Silicon / M1 上。
You probably have GOROOT
maunally set in your .bash_profile
or .zshrc
to something like GOROOT="/usr/local/opt/go/libexec"
.您可能在.bash_profile
或 .zshrc 中手动将GOROOT
设置为类似.zshrc
GOROOT="/usr/local/opt/go/libexec"
的内容。
It would now be:现在是:
export GOROOT=/opt/homebrew/opt/go/libexec
Brew changed dir from /usr/local/opt
to /opt/homebrew/opt
for M1 arm builds. Brew 将 M1 arm 构建的目录从/usr/local/opt
更改为/opt/homebrew/opt
。
In my case, I installed some go tool using brew (brew install golangci-lint).就我而言,我使用 brew 安装了一些 go 工具(brew install golangci-lint)。 This result in installing another go binary.这导致安装另一个 go 二进制文件。 I fixed the issue by running我通过运行解决了这个问题
brew uninstall go
Ubuntu 18 specific solution: Ubuntu 18 具体解决方案:
golang-backports
:从golang-backports
安装了 Golang 包:sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get install golang-1.15
${HOME}/.bashrc
with:用以下内容更新了我的${HOME}/.bashrc
:export PATH=$PATH:/usr/lib/go-1.15/bin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.