Reputation: 2482
I am getting this error when I tried to run an example helloworld code I got onlie.
compile: version "go1.9" does not match go tool version "go1.9.1"
My computer has go1.9.1. What does the error mean and how can I fix this?
Upvotes: 65
Views: 74022
Reputation: 1
In case you use Goland and need to set project go version distinct from your main go version (like Goland -> Settings -> GOROOT), you may get such error (for example from makefile):
version "go1.20.7" does not match go tool version "go1.21.3"
In this case you should add also GOPATH to your 1.20.7 installation: Goland -> Settings -> GOPATH -> Project GOPATH
Upvotes: 0
Reputation: 26838
For IntelliJ or Goland user, if this happened to you in the built in terminal (but works fine in another terminal), change the go version in the settings.
compile: version "go1.20.7" does not match go tool version "go1.21.3"
then restart your IDE.
Upvotes: 3
Reputation: 1
I had the same issue when I used getgo to update my Go version from 1.19 to 1.20. In my case, getgo created a .bash_profile and set its own export path w/c is not consistent with what's in my .bashrc.
#my .bash_profile;
export PATH=$PATH:/home/user/.go/bin
export PATH=$PATH:/home/user/go/bin
#my .bashrc;
export GOROOT=/usr/local/go/
export GOPATH=$HOME/go
export PATH=$PATH:$/home/user/go/bin:$GOROOT/bin:$PATH
SOLUTION: I just replaced my export PATH in bashrc w/
export PATH=$PATH:$/home/user/.go/bin:$GOROOT/bin:$PATH
<Note the '.go' change w/c is now consistent to what's in my .bash_profile>.
So whether source is ~/.bashrc or ~/.bash_profile, it will always point to the same path for Go. Hope this helps. I'm also new to Go and Ubuntu. I know how painful it is to get these variables right on your own.
Upvotes: 0
Reputation: 11803
In my case, I had a scripts that look like this:
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
Hanging around in my .bashrc
/.zshrc
file from a previous installation of go / trying to use gvm.
Removing this and restarting terminal solved it for me.
Upvotes: 0
Reputation: 525
For M1 Mac, the following steps helped me!
Check for which go from VSCode Terminal and check from system terminal.
from vscode terminal
user@mac % which go
/usr/local/go/bin/go
from my mac terminal
user@mac % which go
/opt/homebrew/bin/go
Whichever corresponds to the GOROOT shown go env, keep it and delete the other one
user@mac % go env GOROOT
/usr/local/go
in this case
rm -rf /opt/homebrew/bin/go
close and reload the vscode and terminal
Upvotes: 13
Reputation: 7750
For me, it's caused by GOROOT env, using gotip before, change to brew version.
# curret go env
cat "$(go env GOENV)"
# make sure this is correct
go env GOROOT
# unset GOROOT if setted before
go env -u GOROOT
you may also want to set a proper GOROOT to match the go version.
Upvotes: 0
Reputation: 28285
This error happens when you forgot to delete previous golang install ... just delete its directory ... so identify go install location ... on linux issue
type go
typical output is
go is hashed (/usr/local/go/bin/go)
so just remove its grandparent directory ( go install dir not just the go binary )
sudo rm -rf /usr/local/go # NOTE this is not /usr/local/go/bin/go
now just install go and you'll be fine
Upvotes: 5
Reputation: 1945
If you are installing using OSX homebrew you may need to set the $GOROOT
in your .bashrc
, .zshrc
, etc:
export GOROOT=/usr/local/opt/go/libexec
I had the same error this morning when I updated from 1.9 -> 1.9.1 though according to several post the $GOROOT
shouldn't have to be set and I had not set it until today. This may be a bug?
Edit: not a bug, for more details see answer below.
Upvotes: 65
Reputation: 301
if you use VsCode, you just add this in setting.json.
"go.goroot": "/usr/local/Cellar/go/1.x.x/libexec",
Upvotes: 0
Reputation: 454
Took a simple approach(Linux), I had different versions of Go installed in my system.
$ whereis go
helped me to find the available go runnables, removed all, installed a fresh one and ensured to create a link for this new Go runnable in one of the $PATH folder to ensure below gives the correct version of what installed now.
$ go version
Upvotes: -1
Reputation: 639
This is a mismatch between the GOROOT
environment variable and the default path to your go
command. One or the other needs to be changed; the one that needs to be changed depends on the specific setup on your computer. You could determine this by updating your Go to the latest version using your preferred method, running either which go
(on Linux/macOS/BSD) or where go
(on Windows), and then checking which of the files listed has the newer timestamp.
GOROOT
to match the default path of your go
command, run type go
and strip off the /bin/go
part at the end to yield the directory path containing your Go installation. Then, add it to your .bashrc
or other appropriate init file like this:export GOROOT=/path/to/go-installation
go
command path to match your GOROOT
, add this to the bottom of your init file:export PATH="${GOROOT}/bin:${PATH}"
To change the GOROOT
to match the default path of your go
command, run where go
take the first line of output, and strip off the \bin\go.exe
part at the end. Then, go to "Edit the system environment variables" in Settings, click "Environment Variables...", find the "GOROOT" variable and edit to read the path you created earlier.
To instead change the go
command path to match your GOROOT
, first save the output of echo %GOROOT%\bin
. Then, go to "Edit the system environment variables" in Settings, click "Environment Variables...", and find the
find the "Path" row in the bottom pane, click New, put in the path you created earlier, and finally click Move Up until it's at the top.
You'll need to open up a new command prompt to see the effects.
Upvotes: 42
Reputation: 2780
For Windows delete the GOROOT System variables in the Enviroment Variables and restart the PC.
Upvotes: 0
Reputation: 221
In mac OS , if you downloaded and installed go package without brew, running brew update commands will cause this problem to occur for fix this problem you can do : brew uninstall --ignore-dependencies go uninstalling go from brew will fix problem
Upvotes: 14
Reputation: 625
in case you are using mac with homebrew, just run:
brew cleanup
to clean all the legacy package, this fixed my problem.
Upvotes: 19