...

起步

Download the Go distribution

下载Go发行版

Official binary distributions are available for the FreeBSD (release 8-STABLE and above), Linux, Mac OS X (Snow Leopard and above), and Windows operating systems and the 32-bit (386) and 64-bit (amd64) x86 processor architectures.

官方二进制发行版 支持 FreeBSD(8-STABLE 发行版及以上)、Linux、Mac OS X(Snow Leopard 及以上)和 Windows 操作系统以及32位(386)和64位(amd64)的 x86 处理器架构。

If a binary distribution is not available for your combination of operating system and architecture, try installing from source or installing gccgo instead of gc.

若在你的操作系统和架构上没有可用的二进制发行版,请尝试 从源码安装Go安装gccgo来代替gc

System requirements

系统需求

The gc compiler supports the following operating systems and architectures. Please ensure your system meets these requirements before proceeding. If your OS or architecture is not on the list, it's possible that gccgo might support your setup; see Setting up and using gccgo for details.

gc 编译器支持以下操作系统及架构。在开始前,请确保你的系统满足这些需求。 若你的OS及架构不在此列表中,那么 gccgo 可能支持你的设置, 详情请访问设置并使用gccgo

Operating system Architectures Notes

FreeBSD 8-STABLE or later amd64, 386, arm Debian GNU/kFreeBSD not supported; FreeBSD/ARM needs FreeBSD 10 or later
Linux 2.6.23 or later with glibc amd64, 386, arm CentOS/RHEL 5.x not supported; no binary distribution for ARM yet
Mac OS X 10.6 or later amd64, 386 use the gcc that comes with Xcode
Windows XP or later amd64, 386 use MinGW gcc. No need for cygwin or msys.

gcc is required only if you plan to use cgo.
You only need to install the command line tools for Xcode. If you have already installed Xcode 4.3+, you can install it from the Components tab of the Downloads preferences panel.

操作系统 架构 注释

FreeBSD 7或更新 amd64、386、arm 不支持Debian GNU/kFreeBSD;FreeBSD/ARM需要FreeBSD 10或更新
Linux 2.6.23或更新,带glibc amd64、386、arm 不支持CentOS/RHEL 5.x;ARM还没有二进制发行版
Mac OS X 10.6或更新 amd64、386 使用Xcode及其自带gcc
Windows 2000或更新 amd64、386 使用mingw gcc,无需cygwin或msys

仅当你打算用cgo时才需要gcc
只需为 Xcode安装命令行工具即可。 若你已经安装了Xcode 4.3+,只需从下载配置面板的组件标签内安装它即可。

Install the Go tools

安装Go工具

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

若你要从旧版本的Go升级,那么首先必须卸载已存在的版本

Linux, Mac OS X, and FreeBSD tarballs

Linux、Mac OS X 和 FreeBSD 的安装包

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

下载此压缩包并提取到 /usr/local 目录,在 /usr/local/go 中创建Go目录树。例如:

tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

Choose the archive file appropriate for your installation. For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux, the archive you want is called go1.2.1.linux-amd64.tar.gz.

该压缩包的名称可能不同,这取决于你安装的Go版本和你的操作系统以及处理器架构。

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

(此命令必须作为root或通过 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:

要将 /usr/local/go/bin 添加到 PATH 环境变量, 你需要将此行添加到你的 /etc/profile(全系统安装)或 $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.

Go二进制发行版假定它们会被安装到 /usr/local/go (或Windows下的 c:\Go)中,但也可将Go工具安装到不同的位置。 此时你必须设置 GOROOT 环境变量来指出它所安装的位置。

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

例如,若你将Go安装到你的home目录下,你应当将以下命令添加到 $HOME/.profile 文件中:

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

Note: GOROOT must be set only when installing to a custom location.

GOROOT 仅在安装到指定位置时才需要设置。

Mac OS X package installer

Mac OS X安装包

Download the package file, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to /usr/local/go.

打开此包文件 并跟随提示来安装Go工具。该包会将Go发行版安装到 /usr/local/go 中。

The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.

此包应该会将 /usr/local/go/bin 目录放到你的 PATH 环境变量中。 要使此更改生效,你需要重启所有打开的终端回话。

Windows

The Go project provides two installation options for Windows users (besides installing from source): a zip archive that requires you to set some environment variables and an MSI installer that configures your installation automatically.

对于Windows用户,Go项目提供两种安装选项(从源码安装除外): zip压缩包需要你设置一些环境变量,而实验性MSI安装程序则会自动配置你的安装。

MSI installer

MSI安装程序

Open the MSI file and follow the prompts to install the Go tools. By default, the installer puts the Go distribution in c:\Go.

打开此MSI文件 并跟随提示来安装Go工具。默认情况下,该安装程序会将Go发行版放到 c:\Go 中。

The installer should put the c:\Go\bin directory in your PATH environment variable. You may need to restart any open command prompts for the change to take effect.

此安装程序应该会将 c:\Go\bin 目录放到你的 PATH 环境变量中。 要使此更改生效,你需要重启所有打开的命令行。

Zip archive

Zip压缩包

Download the zip file and extract it into the directory of your choice (we suggest c:\Go).

下载此zip文件 并提取到你的自选目录(我们的建议是c:\Go):

If you chose a directory other than c:\Go, you must set the GOROOT environment variable to your chosen path.

若你选择了 c:\Go 之外的目录,你必须为你所选的路径设置 GOROOT 环境变量。

Add the bin subdirectory of your Go root (for example, c:\Go\bin) to your PATH environment variable.

将你的Go根目录中的 bin 子目录(例如 c:\Go\bin)添加到你的 PATH 环境变量中。

Setting environment variables under Windows

在Windows下设置环境变量

Under Windows, you may set environment variables through the "Environment Variables" button on the "Advanced" tab of the "System" control panel. Some versions of Windows provide this control panel through the "Advanced System Settings" option inside the "System" control panel.

在Windows下,你可以通过在系统“控制面板”中,“高级”标签上的“环境变量”按钮来设置环境变量。 Windows的一些版本通过系统“控制面板”中的“高级系统设置”选项提供此控制板。

Test your installation

测试你的安装

Check that Go is installed correctly by building a simple program, as follows.

通过构建一个简单的程序来检查Go的安装是否正确,具体操作如下:

Create a file named hello.go and put the following program in it:

首先创建一个名为 hello.go 的文件,并将以下代码保存在其中:

package main

import "fmt"

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

Then run it with the go tool:

接着通过 go 工具运行它:

$ go run hello.go
hello, world

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

若你看到了“hello, world”信息,那么你的Go已被正确安装。

Set up your work environment

设置你的工作环境变量

You're almost done. You just need to set up your environment.

差不多了,你只要再设置一下就好。

Read the How to Write Go Code document, which provides essential setup instructions for using the Go tools.

请阅读如何使用Go编程,它提供了使用Go工具的基本设置说明

Uninstalling Go

卸载 Go

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

要从你的系统中移除既有的Go安装,需删除 go 目录。 在 Linux、Mac OS X、和 FreeBSD 系统下通常为 /usr/local/go, 在 Windows 下则为 c:\Go

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.

你也应当从你的 PATH 环境变量中移除 Go 的 bin 目录。 在 Linux 和 FreeBSD 下你应当编辑 /etc/profile$HOME/.profile。 若你是通过Mac OS X 包安装的 Go,那么你应当移除 /etc/paths.d/go 文件。 Windows 用户请阅读在 Windows 下设置环境变量一节。

获取帮助

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

要获取实时帮助,请询问 Freenode IRC 上 #go-nuts 中的 Gopher 们。

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

Go 语言的官方讨论邮件列表为 Go Nuts

Report bugs using the Go issue tracker.

请使用Go 问题跟踪器报告Bug。