Getting Started
入门
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.
tar -C /usr/local -zxf go$VERSION.$OS-$ARCH.tar.gz
下载归档文件并将它提取至/usr/local/go
,举个例子。
tar -C /usr/local -zxf 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.
选择适合你安装的归档文件。例如,如果你想在64-bit x86的Linux主机上安装1.2.1版本的Go,则你所需要的归档文件称为go1.2.1 linux-amd64.tar.gz
(Typically these commands be run as 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
:
exprot PATH=$PATH:/usr/local/go/bin
将/usr/local/go/bin
添加至PATH环境变量中。你可以将此行添加到/etc/progile
(全局安装)或者$HOME/.profile
:
exprot PATH=$PATH:/usr/local/go/bin
Installing to a custom location
自定义位置安装
The Go binary distributions assume they will be installed in
/usr/local/go
(orc:\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
(或者在Winodws安装在c:\Go
),但是允许把Go工具安装在一个不同的位置。在这种情况下,你必须将GOROOT环境变量设置为安装的路径。
For example, if you installed Go to your home directory you should add commands like the following to
$HOME/.profile
:
export GOROOT=$HOME/go1.x
export PATH=$PATH:$GOROOT/bin
举一个例子,如果你将Go安装至home目录下,你需要在$HOME/.profile
文件中添加以下命令:
export GOROOT=$HOME/go1.x
export PATH=$PATH:$GOROOT/bin
Note: GOROOT must be set only when installing to a custom location.
注意:GOROOT只有在安装到自定义位置时才能设置。