I had installed go on my Ubuntu desktop and it worked fine before I switch off the computer.
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
sudo apt-get install golang-docI had install go directly by downloading go1.10.1.linux-amd64.tar.gz file, not using apt-get
go env
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 version go1.10.1 linux/amd64I can still run comiled go code.
What could have gone wrong here? How can I fix it?
611 Answers
It may seem odd, but running export GOROOT= fixed the issue for me.
The compile program should be in your go env GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" directory. If not, download Go, delete /usr/local/go, and reinstall Go.
I was facing the same issue in my MAC M1.
Previously, I had downloaded it using "brew". I tried downloading it manually and reinstalling it. That worked for me.
go version: 1.18.2 Download:
On Apple Silicon / M1.
You probably have GOROOT maunally set in your .bash_profile or .zshrc to something like GOROOT="/usr/local/opt/go/libexec".
It would now be:
export GOROOT=/opt/homebrew/opt/go/libexecWhy?
Brew changed dir from /usr/local/opt to /opt/homebrew/opt for M1 arm builds.
Downloading .tar.gz versus using apt-get may cause go env values conflicts/overrides. Better to stick to one installation approach.
I had faced a similar problem in 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).
Analysis:
If you do the following:
go env | grep GOTOOLDIR
cd <value of GOTOOLDIR>
lsYou should see the following (notice the compile binary):
addr2line buildid cover fix objdump test2jsonapi
cgo dist link pack trace
asm compile doc nm pprof vetIf you don't, then you have probably switched to the wrong/overwritten/earlier Go installation.
Solution:
- If you are using an IDE, it's easy to switch among multiple Go SDKs by going to Settings or Preferences. Then restart the Terminal in IDE
- If you are not using an IDE, a simple solution is to uninstall both the Go installations. Then reinstall Go using only one method. And use the same method to install any other Go related stuff.
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.
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.
I ran into a similar issue, but on a different system than op, windows+cygwin to be exact.
The issue for me was that the files inside the tools folder were not marked as executable.
To solve this:
- go to the tools directory (see Abhinav Sureka solution)
chmod a+x *
In my case, I installed some go tool using brew (brew install golangci-lint). This result in installing another go binary. I fixed the issue by running
brew uninstall go first go with locate addr2lineIf it will show you/usr/lib/go-1.20/pkg/tool/linux_amd64/addr2lineabove line then
copy all content from linux_amd64 folder to /usr/local/go/pkg/tool/linux_amd64/ folder using below commandsudo cp linux_amd64/* /usr/local/go/pkg/tool/linux_amd64/
Now try with go run or go build command it will work
For me, it was that I had installed the go binary for the wrong architecture . I needed go1.18.4.darwin.arm64, not go1.18.4.darwin.amd64.
Ubuntu 18 specific solution:
- removed manually installed Go SDK and Go SRC
- removed manually set GOROOT variable
- installed Golang package from
golang-backports:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get install golang-1.15- Updated my
${HOME}/.bashrcwith:
export PATH=$PATH:/usr/lib/go-1.15/bin- Rebooted the OS