I am using M2, and use brew installed go 1.20. Now I want to switch Go version in VSCode:
But it failed with this warning message:
Switching Go version when process.env["GOROOT"] is set is unsupported.
After removing GOROOT
from .zshrc
, GOROOT
has been disapeared from env
. But it still exist in go env
. How can I remove GOROOT
from go env
? I also tried to remove it from ${HOME}/Library/Application Support/go/env
, but I still can not switch Go version.
➜ ~ env |grep GOROOT
➜ ~ go env GOROOT
/usr/local/go
Choose Go Environment is a feature of the vscode-go extension (see Managing Your Go Version).
If after removing GOROOT
from .zshrc
, the output from env | grep GOROOT
is empty, then you have done the right thing to make the feature work.
Bear in mind that the change won't be observed by VSCode immediately. It's required to restart VSCode. The tricky thing is, if VSCode is started by a process that has GOROOT
set, VSCode will still see it. So maybe it's better to restart the system to be safe.
Now I have to set "go.goroot" in settings.json to change the go version.
You should remove this configuration after restart VSCode or reboot the system. Otherwise, you will get this warning:
Switching Go version when "go.goroot" is set is unsupported.
But it still exist in
go env
. How can I removeGOROOT
fromgo env
.
This is expected. You don't need to, and can't, remove it from the output of go env
.
go env GOROOT
shows the effective setting of GOROOT
. It shows the value from one of the following sources (higher priority first):
go
command. For example, if you have go1.19 installed with go install golang.org/dl/go1.19@latest
, running go1.19 env GOROOT
will give you the path like $HOME/sdk/go1.19
.GOROOT
environment variable;go env GOENV
shows the path to the configuration file).go
command found in the PATH
parts (this is a little confusing compared to point 1 above).