Golang: 入门 – “go” 不被识别为内部或外部命令

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

Golang: Getting started - "go" is not recognized as an internal or external command"

问题

尝试开始使用Go,但我无法正确设置工作环境。

英文:

Trying to get started with Go but I cant manage to set up the work environnement properly.

答案1

得分: 12

你将'GOROOT'设置错误了。将其设置为C:\Go\。

将C:\Go\bin添加到你的'Path'中。

英文:

EDITED for future reference.

  1. You set your 'GOROOT' wrong. Set it to C:\Go\

  2. Include C:\Go\bin to your 'Path'

答案2

得分: 11

除了@Xeph的回答之外,还要确保如果你最近安装了Go语言,你要使用一个新的终端/cmd窗口。

英文:

Aside from @Xeph's answer, just make sure if you recently installed Go that you use a fresh terminal/cmd window.

答案3

得分: 4

运行命令"go env"并检查变量"gopath"的路径,这就是你应该保存项目的地方。否则,如果你运行go命令,你会得到错误信息"go is not recognized as internal or external command"。

英文:

Run command "go env" and check the path for variable "gopath" that's where you should keep your project. Else where if you run go command you will get error "go is not recognized as internal or external command"

答案4

得分: 2

以下是翻译好的内容:

这是让我成功运行的步骤,假设你在 Windows 10 上的全新 GO 安装中没有做任何更改。

  1. 在用户变量中设置 GOROOT:C:\Go\
  1. 在用户变量中添加路径:%USERPROFILE%\Go\bin
  1. 在系统变量中添加路径:C:\Go\bin
英文:

here's what made it work for me, assuming you hadnt change anything from a fresh GO install in windows 10.

  1. set GOROOT in user variables: C:\Go\
  1. add path in user variables: %USERPROFILE%\Go\bin
  1. add path in system variables: C:\Go\bin

答案5

得分: 1

我阅读了各种答案和文章,对我最有帮助的步骤如下:

  1. 我的电脑 -> 右键点击 -> 属性
  2. 高级系统设置 -> 环境变量
  3. 在系统变量部分 -> 新建 -> GOPATH -> 项目位置
  4. 选择路径 -> 新建 -> 安装的Go的bin目录的路径
  5. 保存并关闭。
  6. 重新启动命令提示符/系统。
  7. 在命令提示符中运行go命令以检查是否正常工作
英文:

I read various answers as well articles and most effective steps that helped me were :

  1. My Computer -> RC -> Properties
  2. Advanced System Settings -> Environment Variables
  3. Under System Variables Section -> New -> GOPATH -> Project Location
  4. Select Path -> New ->path to bin of installed go
  5. Save and close.
  6. Restart the cmd / system .
  7. Run go in the cmd to check the working .

答案6

得分: 1

如果即使添加了环境变量后仍然无法解决问题,你可以检查是否已经安装了VSCode的Go扩展,如果还没有,请安装它。然后,在工作目录中创建一个新的GO文件,会弹出"gopls命令不可用"的提示,点击"install all"以在VSCode内获得完整支持。我是通过这种方式解决了这个问题,希望能对你有帮助。

英文:

If you are not able to solve the problem even after adding environment variables, you can check if you have installed Go extension from VSCode, install it if you haven't already. Then, when you create a new GO file to work in the working directory, "gopls command not available" will be popped up,click install all to get full support inside VSCode.
I solved the issue like this, I hope that helps.

答案7

得分: 0

你需要将路径变量设置为从C:\Users\YourUser\goC:\Users\YourUser\,然后你就可以在命令行中使用go version命令查看你的Go版本。

英文:

You need to set path var like from C:\Users\YourUser\go to C:\Users\YourUser\ then you can see your go version in your command line go version

huangapple
  • 本文由 发表于 2016年4月10日 17:43:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/36528186.html
匿名

发表评论

匿名网友

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

确定