如何修复错误的变量”go env GOROOT”?

huangapple go评论77阅读模式
英文:

How to fix wrong variables "go env GOROOT"?

问题

我犯了一个错误:

go env -w GOROOT=/Users/apple/Documents/testProject/GXB_be:/usr/local/go

我将一个错误的路径设置为了go env的变量。这使得我几乎无法在vscode终端中使用go env命令,所以我无法直接使用该命令来修复它。

% go env
go: cannot find GOROOT directory: /Users/apple/Documents/testProject/GXB_be:/usr/local/go

我参考了这个文档https://go.dev/doc/install,尝试重新安装go,并尝试重新启动vscode终端,甚至是macbook,但都没有起作用。

我认为这是一个全局性的问题,因为它不仅影响到了vscode,还出现在终端上。

我的环境:
go版本 go1.19.3 darwin/amd64
vscode 1.72.2 (Universal)

现在我通过导入环境变量临时解决了这个问题。然而,每次创建新的vscode终端时,问题仍然存在。

% go env
go: cannot find GOROOT directory: /Users/apple/Documents/testProject/GXB_be:/usr/local/go
% export GOROOT=/usr/local/go
% go env
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
...

我该如何恢复环境?

英文:

I made a mistake:

go env -w GOROOT=/Users/apple/Documents/testProject/GXB_be:/usr/local/go

I set a wrong path as a variable of go env.
This makes it almost impossible for me to use the go env command in the vscode terminal,so I cannot directly use this command to repair it.

% go env
go: cannot find GOROOT directory: /Users/apple/Documents/testProject/GXB_be:/usr/local/go

I refer to this document https://go.dev/doc/install , tried to reinstall go, and tried to restart the vscode terminal, or even the macbook, but it did not work.

I think this is a global problem, because it not only affects vscode, but also occurs on the terminal.

My environment:
go version go1.19.3 darwin/amd64
vscode 1.72.2 (Universal)

Now I have temporarily solved this problem by importing environment variables.
However, every time a new vscode terminal is created, the problem still exists.

% go env
go: cannot find GOROOT directory: /Users/apple/Documents/testProject/GXB_be:/usr/local/go
% export GOROOT=/usr/local/go
% go env
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
...

How can I restore the environment?

答案1

得分: 1

从 Volker 中删除(或编辑)/Users//Library/Application Support/go/env。

英文:

Remove (or edit) /Users/<you>/Library/Application Support/go/env.
-- from Volker

huangapple
  • 本文由 发表于 2022年11月6日 21:36:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/74336353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定