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)
As Go uses open-source (FREE!) repositories often, be sure to install the Git package here first.
由于Go經常使用開源(FREE!)存儲庫,因此請確保首先在此處安裝Git軟件包。
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集。
- Follow the instructions on the Go installation program. 按照Go安裝程序上的說明進行操作。
- Run the Command Prompt on your computer by searching for “cmd”. Open the command line and type: “go version” 通過搜索“ cmd”在計算機上運行命令提示符。 打開命令行并輸入:“ go version”
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/