如何设置Windows版Go —快速简便的指南

by Linda Gregier

琳达·格雷格(Linda Gregier)

Another great language to add to your full-stack developer tool belt is the simple and productive general-purpose programming language of Go.

添加到您的全栈开发人员工具带中的另一种很棒的语言是Go的简单而高效的通用编程语言。

Through a project started in 2007, Go came to fruition through the efforts of some Google programmers. They took great care in Go’s design to make it clear and consistent in its language features and standard libraries, making Go easy and fun to use.

通过2007年启动的一个项目,Go在一些Google程序员的努力下得以实现。 他们在Go的设计中格外小心,以使其语言功能和标准库清晰且一致,从而使Go易于使用且有趣

It’s open-source at it’s best…but don’t forget: it’s case-sensitive!

最好是开源的……但不要忘记:它区分大小写!

So let’s get started on the Microsoft Windows 10 operating system. You’ll see just how easy this really is — only a basic working knowledge of GitHub and the command prompt is required. Sure there are other ways of installing and running the program, but with limited coding background I felt this set of instructions was the easiest to understand and follow.

因此,让我们开始使用Microsoft Windows 10操作系统。 您会看到这真的很容易-只需具备GitHub的基本工作知识和命令提示符即可。 当然,还有其他安装和运行程序的方法,但是在有限的编码背景下,我觉得这组说明最容易理解和遵循。

Be sure to follow these steps in their entirety as well as in the correct order (as listed) to save yourself from having to uninstall Go and spend a few hours troubleshooting any installation-related issues.

请确保完整并按照正确的顺序(如所列)执行这些步骤,以免去卸载Go并花几个小时对所有与安装有关的问题进行故障排除。

阶段1:按以下顺序安装以下组件 (Phase 1: Install the following in this order)

  1. As Go uses open-source (FREE!) repositories often, be sure to install the Git package here first.

    由于Go经常使用开源(FREE!)存储库,因此请确保首先在此处安装Git软件包。

  2. Navigate to the Go installation website here. Download and install the latest 64-bit Go set for Microsoft Windows OS.

    在此处导航到Go安装网站。 下载并安装适用于Microsoft Windows OS的最新64位Go集。

  3. Follow the instructions on the Go installation program.

    按照Go安装程序上的说明进行操作。
  4. Run the Command Prompt on your computer by searching for “cmd”. Open the command line and type: “go version”

    通过搜索“ cmd”在计算机上运行命令提示符。 打开命令行并输入:“ go version”
  5. The output after entering go version should look like this:

    输入go版本后的输出应如下所示:

阶段2:创建Go工作区 (Phase 2: Creating your Go work-space)

First, confirm your Go binaries: go to your computer’s Control Panel, then to System and Security > System > Advanced system settings, and on the left-hand pane click the Advanced tab. Then click on Environmental Variables on the bottom-right-hand side. Ensure Path under System Variables has the “C:\Go\bin” variable in it.

首先,确认您的Go二进制文件:转到计算机的“控制面板”,然后转到“系统和安全性”>“系统”>“高级”系统设置,然后在左侧窗格中单击“高级”选项卡。 然后单击右下角的环境变量。 确保系统变量下的路径中包含“ C:\ Go \ bin”变量。

Then create your Go work-space. This will be in a separate and new folder from where the Go installation files are saved. For example, your G installation files were saved under the path C:\Go and you are creating your Go work-space under C:\Projects\Go

然后创建您的Go工作区。 该文件将保存在一个单独的新文件夹中,其中保存了Go安装文件。 例如,您的G安装文件保存在路径C:\ Go下,并且您正在C:\ Projects \ Go下创建Go工作区。

In your new Go work-space folder, set up three new folders:

在新的Go工作区文件夹中,设置三个新文件夹:

阶段3:创建GOPATH环境变量 (Phase 3: Create the GOPATH environment variable)

Create the GOPATH variable and reference your newly-created Go work-space. Go back to your Control Panel and navigate to System and then Environmental Variables. Then under System Variables click on New.

创建GOPATH变量并引用您新创建的Go工作空间。 返回控制面板并导航至“系统”,然后导航至“环境变量”。 然后在“系统变量”下单击“新建”。

Next to Variable Name, enter “GOPATH,” and next to Variable Value enter “C:\Projects\Go”

在“变量名称”旁边,输入“ GOPATH”,在“变量值”旁边输入“ C:\ Projects \ Go”

To check that your path has been set correctly, enter “echo %GOPATH%” on the command line.

要检查路径设置是否正确,请在命令行上输入“ echo%GOPATH%”。

阶段4:测试并确保 (Phase 4: Test and ensure)

Now you’re ready to verify that all is working correctly by opening the command line and typing: go get github.com/golang/example/hello

现在,您可以通过打开命令行并键入以下命令来验证所有组件是否正常工作: go get github.com/golang/example/hello

Wait for the code to be entirely implemented (this could take a few seconds), then enter in the following in the command line: %GOPATH%/bin/hello

等待代码完全实现(这可能需要几秒钟),然后在命令行中输入以下内容: %GOPATH%/bin/hello

If the installation was successful, you should get the following return message: “Hello, Go examples!”

如果安装成功,您将收到以下返回消息:“ Hello,Go examples!”

I hope you are successful. And if you run into any errors or confusing messages, comment below with the results of this command line: “go env”

希望你成功。 并且,如果您遇到任何错误或令人困惑的消息,请在下面用此命令行的结果进行注释:“ go env”

Inspiration for this article came from the following on-line resources which were very easy to understand and helpful when setting up Go on my Windows operating system:

本文的灵感来自以下在线资源,这些资源在我的Windows操作系统上设置Go时非常容易理解和帮助:

Wade Wegner’s visually-simple & stylistic article

韦德·韦格纳(Wade Wegner)的视觉上简单且风格独特的文章

And now you’re ready to become a “Gopher”!

现在您已准备好成为“地鼠”!

翻译自: https://www.freecodecamp.org/news/setting-up-go-programming-language-on-windows-f02c8c14e2f/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值