Golang命令无法正常工作。

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

Golang Commands not working

问题

我刚开始学习Golang,对它的了解非常有限。

我点击了下面的链接,并将箭头指向的包上传到了我的电脑上。

https://golang.org/dl/

之后,我在桌面上创建了一个名为"golang"的文件夹,如下图所示。

Golang命令无法正常工作。

我在Visual Studio Code中打开了这个文件夹,并下载了下面的附加组件。

Golang命令无法正常工作。

最后,我编写了以下代码,并在运行"go run main.go"命令后运行了代码。但是我编写的代码没有起作用。

Golang命令无法正常工作。

问题:
我对Golang有点困惑。我应该怎么做才能运行这段代码?我做错了什么吗?

谢谢

英文:

I just started learning golang.I have very little knowledge.

I have clicked on the link below and uploaded the package indicated by the arrow in the picture to my computer

https://golang.org/dl/

Golang命令无法正常工作。

After that

I created a folder called golang on my desktop as shown in the picture below.

Golang命令无法正常工作。

I open this folder on visual studio code and i have downloaded below addition.

Golang命令无法正常工作。

Finally I wrote the following code and after I ran the cod "go run main.go".
But the code I wrote did not work.

Golang命令无法正常工作。

Question:
It came to me a little confused golang.What do i have to do to run this code what am i doing wrong?

Thanks

答案1

得分: 1

这是要翻译的内容:

显然它不在路径上。我认为Windows安装程序会正确添加它,所以这有点奇怪。不过你可以通过以下方法修复:进入控制面板 -> 系统 -> 高级(选项卡)-> 环境变量(在你的Windows版本中实际名称可能有所不同,但应该是相似的。在最坏的情况下,可以在谷歌中搜索“设置环境变量+你的Windows版本”)。然后找到PATH变量并添加go可执行文件的路径。你还需要设置GOROOT变量。

例如,我将Go安装在C:\Go文件夹中。所以,我设置了GOROOT变量为C:\Go,并将C:\Go\bin添加到PATH变量中。你可以将它们设置为用户变量或系统变量。用户变量只对你可见,而系统变量对所有人都可见。这是唯一的区别。

请记住,这只会影响在你更新环境变量设置之后启动的程序。所以,你需要重新启动VS Code才能生效。

英文:

It's obviously not on the path. It's a bit weird as I believe Windows installer adds it properly. You can fix it though, by going to Control Panel -> System -> Advanced (Tab) -> Environment Variables. (Actual names will likely differ in your version of windows, but should be recognizably close. In worst case, search Setting environment variables for your version of windows in google.). Then find PATH variable and add path to the go executable. You'll also need to have GOROOT variable set as well.

For example, I have Go installed in C:\Go folder. So, I have GOROOT variable set as C:\Go and C:\Go\bin added to PATH variable. You can have them as either User or System variables. User ones will be visible only to you, while System ones will be for everyone. That's the only difference.

Keep in mind though that it will only affect programs started after you have updated environment variables settings. So, you'll have to restart VS Code for it to take effect.

huangapple
  • 本文由 发表于 2017年8月3日 18:04:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/45481001.html
匿名

发表评论

匿名网友

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

确定