5步搭建GO环境

Posted 幕三少

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5步搭建GO环境相关的知识,希望对你有一定的参考价值。

Easy Go Programming Setup for Windows

I’ve had to do this more than once recently, so I figured I’d document the simple steps for setting up the Go programming language on Windows. Most of this is simple and straightforward. The only tricky part I found is setting up your GOPATH, which defines a convention for storing and building Go code you write and acquire from open source code repositories.

5 Simple Steps

Follow these five simple steps to install Go.

  1. Make sure you have both Git download and Mercurial download installed. With Go programming you’ll make heavy use of open source repositories.

  2. Download and install the latest 64-bit Go MSI distributable (which sets most of the environmental variables for you). https://golang.org/dl/

    技术分享

    To make things simple, use the default installation path at C:\Go

  3. Ensure the Go binaries (found in C:\Go\bin) are in your Path system environment variables. To check click System, Advanced system settings, Environment Variables... and open Path under System variables:

    技术分享

    An easy way to confirm is to open the command line and type go version:

    技术分享

  4. Setup your Go workspace. This consists of three folders at the root:

     bin/
     pkg/
     src/
    

    I create a C:\Projects\Go folder as my root Go workspace:

    技术分享

  5. Create the GOPATH environment variable and reference your Go workspace path. To add, click System, Advanced system settings, Environment Variables... and click New... under System variables:

    技术分享

    Set the variable name to GOPATH and value to your Go workspace path (e.g. C:\Projects\Go):

    技术分享

    You can quickly check to ensure your path has been set by opening the command line and typing echo %GOPATH% and check the output:

    技术分享

And that’s all it takes! You’re ready to get started.

Verify

Want to quickly test and ensure this is all working as expected? Open the command line and type the following:

go get github.com/golang/example/hello
%GOPATH%/bin/hello

You should see the output as “Hello, Go examples!” (refreshingly, not your typical hello world):

技术分享

I hope this helps!

以上是关于5步搭建GO环境的主要内容,如果未能解决你的问题,请参考以下文章

Windows系统中搭建Go语言开发环境详解

vscode中搭建Golang开发环境(图文并茂)

Go环境搭建

Go环境搭建

从零搭建Go的开发环境

从零搭建Go的开发环境