术语“go”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称

Tra*_*era 6 go visual-studio-code

跑完后...

go run main.go
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

go : The term 'go' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
Run Code Online (Sandbox Code Playgroud)

小智 11

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
Run Code Online (Sandbox Code Playgroud)

将代码写入终端并运行它。解决问题的简单方法。


Tra*_*era 8

已解决:转到 Visual Studio 代码(假设已安装) ctrl + shift + p 打开命令窗口类型

Go:当前的 GOPATH

这应该为您提供一个路径,创建一个名为 GOPATH 的系统环境变量,并将该路径添加到该变量中。

确保系统环境变量设置为:

GOPATH 设置(在我的情况下)为 C:\Users[username]\go

GOROOT 设置为 C:\go\

IDE 是 Visual Studio 代码。

  • 在 Windows 上,Go MSI 将 GOPATH 安装为用户变量而不是系统变量。感谢您的修复。 (2认同)
  • 需要重新启动 VSCode。 (2认同)