【转】GO 环境配置

Getting Started

Your download should begin shortly. If it does not, click this link.

Install the Go tools

If you are upgrading from an older version of Go you must first remove the existing version.

Linux, Mac OS X, and FreeBSD tarballs

Download the archive and extract it into /usr/local, creating a Go tree in /usr/local/go. For example:

tar -C /usr/local -xzf go1.5.3.linux-amd64.tar.gz

(Typically these commands must be run as root or through sudo.)

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile(for a system-wide installation) or $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin
Installing to a custom location

The Go binary distributions assume they will be installed in /usr/local/go (or c:\Go under Windows), but it is possible to install the Go tools to a different location. In this case you must set the GOROOT environment variable to point to the directory in which it was installed.

For example, if you installed Go to your home directory you should add the following commands to$HOME/.profile:

export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin

NoteGOROOT must be set only when installing to a custom location.

Test your installation

Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.

Create a directory to contain your workspace$HOME/work for example, and set the GOPATH environment variable to point to that location.

$ export GOPATH=$HOME/work

You should put the above command in your shell startup script ($HOME/.profile for example) or, if you use Windows, follow the instructions above to set the GOPATH environment variable on your system.

Next, make the directories src/github.com/user/hello inside your workspace (if you use GitHub, substitute your user name for user), and inside the hello directory create a file named hello.go with the following contents:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

Then compile it with the go tool:

$ go install github.com/user/hello

The above command will put an executable command named hello (or hello.exe) inside the bin directory of your workspace. Execute the command to see the greeting:

$ $GOPATH/bin/hello
hello, world

If you see the "hello, world" message then your Go installation is working.

Before rushing off to write Go code please read the How to Write Go Code document, which describes some essential concepts about using the Go tools.

Uninstalling Go

To remove an existing Go installation from your system delete the go directory. This is usually /usr/local/gounder Linux, Mac OS X, and FreeBSD or c:\Go under Windows.

You should also remove the Go bin directory from your PATH environment variable. Under Linux and FreeBSD you should edit /etc/profile or $HOME/.profile. If you installed Go with the Mac OS X package then you should remove the /etc/paths.d/go file. Windows users should read the section about setting environment variables under Windows.

Getting help

For real-time help, ask the helpful gophers in #go-nuts on the Freenode IRC server.

The official mailing list for discussion of the Go language is Go Nuts.

Report bugs using the Go issue tracker.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值