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 remove GOROOT
from go 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):
- the path inferred from the current
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
.
- the
GOROOT
environment variable;
- the value set in the Go environment configuration file (
go env GOENV
shows the path to the configuration file).
- the path inferred from the
go
command found in the PATH
parts (this is a little confusing compared to point 1 above).