|
1 |
| -# 1.1 Go 安装 |
| 1 | +# 1.1 Installation |
2 | 2 |
|
3 |
| -## Go的三种安装方式 |
4 |
| -Go有多种安装方式,你可以选择自己喜欢的。这里我们介绍三种最常见的安装方式: |
| 3 | +## Three ways to install Go |
5 | 4 |
|
6 |
| -- Go源码安装:这是一种标准的软件安装方式。对于经常使用Unix类系统的用户,尤其对于开发者来说,从源码安装可以自己定制。 |
7 |
| -- Go标准包安装:Go提供了方便的安装包,支持Windows、Linux、Mac等系统。这种方式适合快速安装,可根据自己的系统位数下载好相应的安装包,一路next就可以轻松安装了。**推荐这种方式** |
8 |
| -- 第三方工具安装:目前有很多方便的第三方软件包工具,例如Ubuntu的apt-get、Mac的homebrew等。这种安装方式适合那些熟悉相应系统的用户。 |
| 5 | +There are many ways to configure the Go development environment on your computer, and you can choose whichever one you like. The three most common ways are as follows. |
9 | 6 |
|
10 |
| -最后,如果你想在同一个系统中安装多个版本的Go,你可以参考第三方工具[GVM](https://github.com/moovweb/gvm),这是目前在这方面做得最好的工具,除非你知道怎么处理。 |
11 | 7 |
|
12 |
| -## Go源码安装 |
13 |
| -在Go的源代码中,有些部分是用Plan 9 C和AT&T汇编写的,因此假如你要想从源码安装,就必须安装C的编译工具。 |
| 8 | +- Official installation packages. |
| 9 | + - The Go team provides convenient installation packages in Windows, Linux, Mac and other operating systems. This is probably the easiest way to get started. |
| 10 | +- Install it yourself from source code. |
| 11 | + - Popular with developers who are familiar with Unix-like systems. |
| 12 | +- Using third-party tools. |
| 13 | + - There are many third-party tools and package managers for installing Go, like apt-get in Ubuntu and homebrew for Mac. |
| 14 | + |
| 15 | +In case you want to install more than one version of Go on a computer, you should take a look at a tool called [GVM](https://github.com/moovweb/gvm). It is the best tool I've seen so far for accomplishing this task, otherwise you'd have to deal with it yourself. |
14 | 16 |
|
15 |
| -在Mac系统中,只要你安装了Xcode,就已经包含了相应的编译工具。 |
| 17 | +## Install from source code |
16 | 18 |
|
17 |
| -在类Unix系统中,需要安装gcc等工具。例如Ubuntu系统可通过在终端中执行`sudo apt-get install gcc libc6-dev`来安装编译工具。 |
| 19 | +Because some parts of Go are written in Plan 9 C and AT&T assembler, you have to install a C compiler before taking the next step. |
18 | 20 |
|
19 |
| -在Windows系统中,你需要安装MinGW,然后通过MinGW安装gcc,并设置相应的环境变量。 |
| 21 | +On a Mac, if you have installed Xcode, you already have the compiler. |
20 | 22 |
|
21 |
| -你可以直接去官网[下载源码](http://golang.org/dl/),找相应的`goVERSION.src.tar.gz`的文件下载,下载之后解压缩到`$HOME`目录,执行如下代码: |
| 23 | +On Unix-like systems, you need to install gcc or a similar compiler. For example, using the package manager apt-get (included with Ubuntu), one can install the required compilers as follows: |
22 | 24 |
|
23 |
| - cd go/src |
24 |
| - ./all.bash |
25 |
| - |
26 |
| -运行all.bash后出现"ALL TESTS PASSED"字样时才算安装成功。 |
27 |
| - |
28 |
| -上面是Unix风格的命令,Windows下的安装方式类似,只不过是运行`all.bat`,调用的编译器是MinGW的gcc。 |
29 |
| - |
30 |
| -如果是Mac或者Unix用户需要设置几个环境变量,如果想重启之后也能生效的话把下面的命令写到`.bashrc`或者`.zshrc`里面, |
31 |
| - |
32 |
| - export GOPATH=$HOME/gopath |
33 |
| - export PATH=$PATH:$HOME/go/bin:$GOPATH/bin |
34 |
| - |
35 |
| -如果你是写入文件的,记得执行`bash .bashrc`或者`bash .zshrc`使得设置立马生效。 |
36 |
| - |
37 |
| -如果是window系统,就需要设置环境变量,在path里面增加相应的go所在的目录,设置gopath变量。 |
38 |
| - |
39 |
| -当你设置完毕之后在命令行里面输入`go`,看到如下图片即说明你已经安装成功 |
40 |
| - |
41 |
| - |
| 25 | + `sudo apt-get install gcc libc6-dev` |
42 | 26 |
|
43 |
| -图1.1 源码安装之后执行Go命令的图 |
| 27 | +On Windows, you need to install MinGW in order to install gcc. Don't forget to configure your environment variables after the installation has completed.( ***Everything that looks like this means it's commented by a translator: If you are using 64-bit Windows, you should install the 64-bit version of MinGW*** ) |
44 | 28 |
|
45 |
| -如果出现Go的Usage信息,那么说明Go已经安装成功了;如果出现该命令不存在,那么可以检查一下自己的PATH环境变中是否包含了Go的安装目录。 |
| 29 | +The Go team uses [Mercurial](http://mercurial.selenic.com/downloads/) to manage their source code, so you need to install this tool in order to download the Go source code. |
46 | 30 |
|
47 |
| -> 关于上面的GOPATH将在下面小节详细讲解 |
| 31 | +At this point, execute the following commands to clone the Go source code and compile it.( ***It will clone the source code to your current directory. Switch your work path before you continue. This may take some time.*** ) |
48 | 32 |
|
49 |
| -## Go标准包安装 |
50 |
| - |
51 |
| -Go提供了每个平台打好包的一键安装,这些包默认会安装到如下目录:/usr/local/go (Windows系统:c:\Go),当然你可以改变他们的安装位置,但是改变之后你必须在你的环境变量中设置如下信息: |
52 |
| - |
53 |
| - export GOROOT=$HOME/go |
54 |
| - export GOPATH=$HOME/gopath |
55 |
| - export PATH=$PATH:$GOROOT/bin:$GOPATH/bin |
56 |
| - |
57 |
| -上面这些命令对于Mac和Unix用户来说最好是写入`.bashrc`或者`.zshrc`文件,对于windows用户来说当然是写入环境变量。 |
58 |
| - |
59 |
| -### 如何判断自己的操作系统是32位还是64位? |
60 |
| - |
61 |
| -我们接下来的Go安装需要判断操作系统的位数,所以这小节我们先确定自己的系统类型。 |
62 |
| - |
63 |
| -Windows系统用户请按Win+R运行cmd,输入`systeminfo`后回车,稍等片刻,会出现一些系统信息。在“系统类型”一行中,若显示“x64-based PC”,即为64位系统;若显示“X86-based PC”,则为32位系统。 |
64 |
| - |
65 |
| -Mac系统用户建议直接使用64位的,因为Go所支持的Mac OS X版本已经不支持纯32位处理器了。 |
| 33 | + hg clone -u release https://code.google.com/p/go |
| 34 | + cd go/src |
| 35 | + ./all.bash |
| 36 | + |
| 37 | +A successful installation will end with the message "ALL TESTS PASSED." |
66 | 38 |
|
67 |
| -Linux系统用户可通过在Terminal中执行命令`arch`(即`uname -m`)来查看系统信息: |
| 39 | +On Windows, you can achieve the same by running `all.bat`. |
68 | 40 |
|
69 |
| -64位系统显示 |
| 41 | +If you are using Windows, the installation package will set your environment variables automatically. In Unix-like systems, you need to set these variables manually as follows. ( ***If your Go version is greater than 1.0, you don't have to set $GOBIN, and it will automatically be related to your $GOROOT/bin, which we will talk about in the next section***) |
70 | 42 |
|
71 |
| - x86_64 |
| 43 | + export GOROOT=$HOME/go |
| 44 | + export GOBIN=$GOROOT/bin |
| 45 | + export PATH=$PATH:$GOROOT/bin |
72 | 46 |
|
73 |
| -32位系统显示 |
| 47 | +If you see the following information on your screen, you're all set. |
74 | 48 |
|
75 |
| - i386 |
| 49 | + |
76 | 50 |
|
77 |
| -### Mac 安装 |
| 51 | +Figure 1.1 Information after installing from source code |
78 | 52 |
|
79 |
| -访问[下载地址][downlink],32位系统下载go1.4.2.darwin-386-osx10.8.pkg,64位系统下载go1.4.2.darwin-amd64-osx10.8.pkg,双击下载文件,一路默认安装点击下一步,这个时候go已经安装到你的系统中,默认已经在PATH中增加了相应的`~/go/bin`,这个时候打开终端,输入`go` |
| 53 | +Once you see the usage information of Go, it means you have successfully installed Go on your computer. If it says "no such command", check that your $PATH environment variable contains the installation path of Go. |
80 | 54 |
|
81 |
| -看到类似上面源码安装成功的图片说明已经安装成功 |
| 55 | +## Using the standard installation packages |
82 | 56 |
|
83 |
| -如果出现go的Usage信息,那么说明go已经安装成功了;如果出现该命令不存在,那么可以检查一下自己的PATH环境变中是否包含了go的安装目录。 |
| 57 | +Go has one-click installation packages for every supported operating system. These packages will install Go in `/usr/local/go` (`c:\Go` in Windows) by default. Of course this can be modified, but you also need to change all the environment variables manually as I've shown above. |
84 | 58 |
|
85 |
| -### Linux 安装 |
| 59 | +### How to check if your operating system is 32-bit or 64-bit? |
86 | 60 |
|
87 |
| -访问[下载地址][downlink],32位系统下载go1.4.2.linux-386.tar.gz,64位系统下载go1.4.2.linux-amd64.tar.gz, |
| 61 | +Our next step depends on your operating system type, so we have to check it before we download the standard installation packages. |
88 | 62 |
|
89 |
| -假定你想要安装Go的目录为 `$GO_INSTALL_DIR`,后面替换为相应的目录路径。 |
| 63 | +If you are using Windows, press `Win+R` and then run the command tool. Type the `systeminfo` command and it will show you some useful system information. Find the line that says "system type" -if you see "x64-based PC" that means your operating system is 64-bit, 32-bit otherwise. |
90 | 64 |
|
91 |
| -解压缩`tar.gz`包到安装目录下:`tar zxvf go1.4.2.linux-amd64.tar.gz -C $GO_INSTALL_DIR`。 |
| 65 | +I strongly recommend downloading the 64-bit package if you are a Mac user, as Go no longer supports pure 32-bit processors on Mac OSX. |
92 | 66 |
|
93 |
| -设置PATH,`export PATH=$PATH:$GO_INSTALL_DIR/go/bin` |
| 67 | +Linux users can type `uname -a` in the terminal to see system information. |
| 68 | +A 64-bit operating system will show the following: |
94 | 69 |
|
95 |
| -然后执行`go` |
| 70 | + <some description> x86_64 x86_64 x86_64 GNU/Linux |
| 71 | + // some machines such as Ubuntu 10.04 will show as following |
| 72 | + x86_64 GNU/Linux |
96 | 73 |
|
97 |
| - |
| 74 | +32-bit operating systems instead show: |
98 | 75 |
|
99 |
| -图1.2 Linux系统下安装成功之后执行go显示的信息 |
| 76 | + <some description> i686 i686 i386 GNU/Linux |
100 | 77 |
|
101 |
| -如果出现go的Usage信息,那么说明go已经安装成功了;如果出现该命令不存在,那么可以检查一下自己的PATH环境变中是否包含了go的安装目录。 |
| 78 | +### Mac |
102 | 79 |
|
103 |
| -### Windows 安装 ### |
| 80 | +Go to the [download page](http://code.google.com/p/go/downloads/list), choose `go1.0.3.darwin-386.pkg` for 32-bit systems and `go1.0.3.darwin-amd64.pkg` for 64-bit systems. Going all the way to the end by clicking "next", `~/go/bin` will be added to your system's $PATH after you finish the installation. Now open the terminal and type `go`. You should see the same output shown in igure 1.1. |
104 | 81 |
|
105 |
| -访问[Google Code 下载页][downlink],32 位请选择名称中包含 windows-386 的 msi 安装包,64 位请选择名称中包含 windows-amd64 的。下载好后运行,不要修改默认安装目录 C:\Go\,若安装到其他位置会导致不能执行自己所编写的 Go 代码。安装完成后默认会在环境变量 Path 后添加 Go 安装目录下的 bin 目录 `C:\Go\bin\`,并添加环境变量 GOROOT,值为 Go 安装根目录 `C:\Go\` 。 |
| 82 | +### Linux |
106 | 83 |
|
107 |
| -**验证是否安装成功** |
| 84 | +Go to the [download page]((http://code.google.com/p/go/downloads/list), choose `go1.0.3.linux-386.tar.gz` for 32-bit systems and `go1.0.3.linux-amd64.tar.gz` for 64-bit systems. Suppose you want to install Go in the `$GO_INSTALL_DIR` path. Uncompress the `tar.gz` to your chosen path using the command `tar zxvf go1.0.3.linux-amd64.tar.gz -C $GO_INSTALL_DIR`. Then set your $PATH with the following: `export PATH=$PATH:$GO_INSTALL_DIR/go/bin`. Now just open the terminal and type `go`. You should now see the same output displayed in figure 1.1. |
108 | 85 |
|
109 |
| -在运行中输入 `cmd` 打开命令行工具,在提示符下输入 `go`,检查是否能看到 Usage 信息。输入 `cd %GOROOT%`,看是否能进入 Go 安装目录。若都成功,说明安装成功。 |
| 86 | +### Windows |
110 | 87 |
|
111 |
| -不能的话请检查上述环境变量 Path 和 GOROOT 的值。若不存在请卸载后重新安装,存在请重启计算机后重试以上步骤。 |
| 88 | +Go to the [download page]((http://code.google.com/p/go/downloads/list), choose `go1.0.3.windows-386.msi` for 32-bit systems and `go1.0.3.windows-amd64.msi` for 64-bit systems. Going all the way to the end by clicking "next", `c:/go/bin` will be added to `path`. Now just open a command line window and type `go`. You should now see the same output displayed in figure 1.1. |
112 | 89 |
|
113 |
| -## 第三方工具安装 |
| 90 | +## Use third-party tools |
114 | 91 |
|
115 | 92 | ### GVM
|
116 | 93 |
|
117 |
| -gvm是第三方开发的Go多版本管理工具,类似ruby里面的rvm工具。使用起来相当的方便,安装gvm使用如下命令: |
| 94 | +GVM is a Go multi-version control tool developed by a third-party, like rvm for ruby. It's quite easy to use. Install gvm by typing the following commands in your terminal: |
118 | 95 |
|
119 |
| - bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) |
| 96 | + bash < <(curl -s https://raw.github.com/moovweb/gvm/master/binscripts/gvm-installer) |
120 | 97 |
|
121 |
| -安装完成后我们就可以安装go了: |
| 98 | +Then we install Go using the following commands: |
122 | 99 |
|
123 |
| - gvm install go1.4.2 |
124 |
| - gvm use go1.4.2 |
| 100 | + gvm install go1.0.3 |
| 101 | + gvm use go1.0.3 |
125 | 102 |
|
126 |
| -也可以使用下面的命令,省去每次调用gvm use的麻烦: |
127 |
| - gvm use go1.4.2 --default |
128 |
| - |
129 |
| -执行完上面的命令之后GOPATH、GOROOT等环境变量会自动设置好,这样就可以直接使用了。 |
| 103 | +After the process has finished, you're all set. |
130 | 104 |
|
131 | 105 | ### apt-get
|
132 |
| -Ubuntu是目前使用最多的Linux桌面系统,使用`apt-get`命令来管理软件包,我们可以通过下面的命令来安装Go,为了以后方便,应该把 `git` `mercurial` 也安装上: |
133 | 106 |
|
134 |
| - sudo apt-get install python-software-properties |
135 |
| - sudo add-apt-repository ppa:gophers/go |
136 |
| - sudo apt-get update |
137 |
| - sudo apt-get install golang-stable git-core mercurial |
| 107 | +Ubuntu is the most popular desktop release version of Linux. It uses `apt-get` to manage packages. We can install Go using the following commands. |
| 108 | + |
| 109 | + sudo add-apt-repository ppa:gophers/go |
| 110 | + sudo apt-get update |
| 111 | + sudo apt-get install golang-stable |
138 | 112 |
|
139 |
| -### homebrew |
140 |
| -homebrew是Mac系统下面目前使用最多的管理软件的工具,目前已支持Go,可以通过命令直接安装Go,为了以后方便,应该把 `git` `mercurial` 也安装上: |
| 113 | +### Homebrew |
141 | 114 |
|
142 |
| - brew update && brew upgrade |
143 |
| - brew install go |
144 |
| - brew install git |
145 |
| - brew install mercurial |
| 115 | +Homebrew is a software management tool commonly used in Mac to manage packages. Just type the following commands to install Go. |
146 | 116 |
|
| 117 | + brew install go |
147 | 118 |
|
148 |
| -## links |
149 |
| - * [目录](<preface.md>) |
150 |
| - * 上一节: [Go环境配置](<01.0.md>) |
151 |
| - * 下一节: [GOPATH 与工作空间](<01.2.md>) |
| 119 | +## Links |
152 | 120 |
|
153 |
| -[downlink]:http://golang.org/dl/ "Go安装包下载" |
| 121 | +- [Directory](preface.md) |
| 122 | +- Previous section: [Go environment configuration](01.0.md) |
| 123 | +- Next section: [$GOPATH and workspace](01.2.md) |
0 commit comments