[Solved] Switching Go version when process.env["GOROOT"] is set is unsupported – Go

by
Ali Hasan
algorithm angular-environmentproviders visual-studio-code

Quick Fix: Simply set "go.goroot" in settings.json to change the go version. 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.

The Problem:

When using M2 with brew-installed Go 1.20, switching Go versions in VSCode fails with the error "Switching Go version when process.env["GOROOT"] is set is unsupported." Removing GOROOT from the environment variables does not resolve the issue, as it persists in go env and ${HOME}/Library/Application Support/go/env.

The Solutions:

Solution 1: Hard restart

Restarting the system or VSCode will resolve the issue. VSCode uses the environment variables that have been set when it was started. If the ` GOROO T ` environment variable has been set when VSCode was started, it will still have that value even after you remove it from the shell environment. By restarting VSCode, it will pick up the new environment variables and the issue will be resolved.

You should also remove the ` “go.goroot” ` configuration from the settings.json file after restarting VSCode. Otherwise, you will get a warning message saying that “Switching Go version when ` “go.goroot” ` is set is unsupported”.

Q&A

How to make Choose Go Environment work and remove the warning switching Go version?

Restart VSCode, remove go.goroot setting, and remove GOROOT from .zshrc.

Where does go env GOROOT show the value from?

It shows from go command, GOROOT env variable, Go environment config file, and PATH parts.

Can I remove GOROOT from go env?

No, because go env shows GOROOT from multiple sources.

Video Explanation:

The following video, titled "Python Tutorial: How to Set the Path and Switch Between Different ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

In this Python Programming Tutorial, we will be learning how to set the PATH environment variable on the Windows Operating Systems.