英文:
Switching Go version when process.env["GOROOT"] is set is unsupported
问题
我正在使用M2,并使用brew安装了Go 1.20。现在我想在VSCode中切换Go版本:
但是它失败了,并显示以下警告信息:
当设置了process.env["GOROOT"]时,不支持切换Go版本。
我从.zshrc
中删除了GOROOT
后,env
中的GOROOT
消失了。但它仍然存在于go env
中。我该如何从go env
中删除GOROOT
?我还尝试从${HOME}/Library/Application Support/go/env
中删除它,但我仍然无法切换Go版本。
➜ ~ env |grep GOROOT
➜ ~ go env GOROOT
/usr/local/go
英文:
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
答案1
得分: 1
选择 Go 环境是 vscode-go 扩展的一个功能(参见管理 Go 版本)。
如果在 .zshrc
文件中移除了 GOROOT
,并且运行 env | grep GOROOT
的输出为空,则说明你已经正确地使该功能生效。
请注意,这个更改不会立即在 VSCode 中生效,需要重新启动 VSCode。有个棘手的问题是,如果 VSCode 是由设置了 GOROOT
的进程启动的,那么 VSCode 仍然会看到它。所以最好重新启动系统以确保安全。
> 现在我必须在 settings.json 中设置 "go.goroot" 来更改 Go 版本。
在重新启动 VSCode 或重新启动系统后,应该删除这个配置。否则,你会收到以下警告:
Switching Go version when "go.goroot" is set is unsupported.
> 但是它仍然存在于 go env
中。我该如何从 go env
中删除 GOROOT
。
这是正常的。你不需要也不能从 go env
的输出中删除它。
go env GOROOT
显示的是 GOROOT
的有效设置。它显示的值来自以下来源(优先级从高到低):
- 当前
go
命令推断的路径。例如,如果你安装了 go1.19,并使用go install golang.org/dl/go1.19@latest
进行安装,运行go1.19 env GOROOT
将会给出类似$HOME/sdk/go1.19
的路径。 GOROOT
环境变量;- Go 环境配置文件中设置的值(
go env GOENV
显示配置文件的路径)。 - 从
PATH
的部分中找到的go
命令推断的路径(与上面的第 1 点相比,这有点令人困惑)。
英文:
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 withgo install golang.org/dl/go1.19@latest
, runninggo1.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 thePATH
parts (this is a little confusing compared to point 1 above).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论