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/

    go1-4-windows-amd64-msi

    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:

    gopath

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

    gopathcmd

  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:

    goworkspace

  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:

    gopathenvvar

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

    gopathvalue

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

    gopathecho

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):

gohelloworld

I hope this helps!

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值