Merging other languages

This commit is contained in:
James Miranda
2016-09-23 18:01:10 -03:00
parent 380a8ee74c
commit de3c5bdaa4
490 changed files with 24539 additions and 24588 deletions

View File

@@ -1,153 +1,123 @@
# 1.1 Go 安装
# 1.1 Installation
## Go的三种安装方式
Go有多种安装方式你可以选择自己喜欢的。这里我们介绍三种最常见的安装方式
## Three ways to install Go
- Go源码安装这是一种标准的软件安装方式。对于经常使用Unix类系统的用户尤其对于开发者来说从源码安装可以自己定制。
- Go标准包安装Go提供了方便的安装包支持Windows、Linux、Mac等系统。这种方式适合快速安装可根据自己的系统位数下载好相应的安装包一路next就可以轻松安装了。**推荐这种方式**
- 第三方工具安装目前有很多方便的第三方软件包工具例如Ubuntu的apt-get、Mac的homebrew等。这种安装方式适合那些熟悉相应系统的用户。
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.
最后如果你想在同一个系统中安装多个版本的Go你可以参考第三方工具[GVM](https://github.com/moovweb/gvm),这是目前在这方面做得最好的工具,除非你知道怎么处理。
## Go源码安装
在Go的源代码中有些部分是用Plan 9 C和AT&T汇编写的因此假如你要想从源码安装就必须安装C的编译工具。
- Official installation packages.
- The Go team provides convenient installation packages in Windows, Linux, Mac and other operating systems. This is probably the easiest way to get started.
- Install it yourself from source code.
- Popular with developers who are familiar with Unix-like systems.
- Using third-party tools.
- There are many third-party tools and package managers for installing Go, like apt-get in Ubuntu and homebrew for Mac.
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.
在Mac系统中只要你安装了Xcode就已经包含了相应的编译工具。
## Install from source code
在类Unix系统中需要安装gcc等工具。例如Ubuntu系统可通过在终端中执行`sudo apt-get install gcc libc6-dev`来安装编译工具。
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.
在Windows系统中你需要安装MinGW然后通过MinGW安装gcc并设置相应的环境变量。
On a Mac, if you have installed Xcode, you already have the compiler.
你可以直接去官网[下载源码](http://golang.org/dl/),找相应的`goVERSION.src.tar.gz`的文件下载,下载之后解压缩到`$HOME`目录,执行如下代码:
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:
`sudo apt-get install gcc libc6-dev`
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*** )
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.
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.*** )
hg clone -u release https://code.google.com/p/go
cd go/src
./all.bash
./all.bash
A successful installation will end with the message "ALL TESTS PASSED."
运行all.bash后出现"ALL TESTS PASSED"字样时才算安装成功。
On Windows, you can achieve the same by running `all.bat`.
上面是Unix风格的命令Windows下的安装方式类似只不过是运行`all.bat`调用的编译器是MinGW的gcc。
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***)
如果是Mac或者Unix用户需要设置几个环境变量如果想重启之后也能生效的话把下面的命令写到`.bashrc`或者`.zshrc`里面,
export GOROOT=$HOME/go
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/gopath
export PATH=$PATH:$HOME/go/bin:$GOPATH/bin
如果你是写入文件的,记得执行`bash .bashrc`或者`bash .zshrc`使得设置立马生效。
如果是window系统就需要设置环境变量在path里面增加相应的go所在的目录设置gopath变量。
当你设置完毕之后在命令行里面输入`go`,看到如下图片即说明你已经安装成功
If you see the following information on your screen, you're all set.
![](images/1.1.mac.png?raw=true)
图1.1 源码安装之后执行Go命令的图
Figure 1.1 Information after installing from source code
如果出现Go的Usage信息那么说明Go已经安装成功了如果出现该命令不存在那么可以检查一下自己的PATH环境变中是否包含了Go的安装目录。
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.
> 关于上面的GOPATH将在下面小节详细讲解
## Using the standard installation packages
## Go标准包安装
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.
Go提供了每个平台打好包的一键安装这些包默认会安装到如下目录/usr/local/go (Windows系统c:\Go),当然你可以改变他们的安装位置,但是改变之后你必须在你的环境变量中设置如下信息:
### How to check if your operating system is 32-bit or 64-bit?
export GOROOT=$HOME/go
export GOPATH=$HOME/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Our next step depends on your operating system type, so we have to check it before we download the standard installation packages.
上面这些命令对于Mac和Unix用户来说最好是写入`.bashrc`或者`.zshrc`文件对于windows用户来说当然是写入环境变量。
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.
### 如何判断自己的操作系统是32位还是64位
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.
我们接下来的Go安装需要判断操作系统的位数所以这小节我们先确定自己的系统类型。
Linux users can type `uname -a` in the terminal to see system information.
A 64-bit operating system will show the following:
Windows系统用户请按Win+R运行cmd输入`systeminfo`后回车稍等片刻会出现一些系统信息。在“系统类型”一行中若显示“x64-based PC”即为64位系统若显示“X86-based PC”则为32位系统。
<some description> x86_64 x86_64 x86_64 GNU/Linux
// some machines such as Ubuntu 10.04 will show as following
x86_64 GNU/Linux
Mac系统用户建议直接使用64位的因为Go所支持的Mac OS X版本已经不支持纯32位处理器了。
32-bit operating systems instead show:
Linux系统用户可通过在Terminal中执行命令`arch`(即`uname -m`)来查看系统信息:
<some description> i686 i686 i386 GNU/Linux
64位系统显示
### Mac
x86_64
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.
32位系统显示
### Linux
i386
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.
### Mac 安装
### Windows
访问[下载地址][downlink]32位系统下载go1.4.2.darwin-386-osx10.8.pkg64位系统下载go1.4.2.darwin-amd64-osx10.8.pkg双击下载文件一路默认安装点击下一步这个时候go已经安装到你的系统中默认已经在PATH中增加了相应的`~/go/bin`,这个时候打开终端,输入`go`
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.
看到类似上面源码安装成功的图片说明已经安装成功
如果出现go的Usage信息那么说明go已经安装成功了如果出现该命令不存在那么可以检查一下自己的PATH环境变中是否包含了go的安装目录。
### Linux 安装
访问[下载地址][downlink]32位系统下载go1.4.2.linux-386.tar.gz64位系统下载go1.4.2.linux-amd64.tar.gz
假定你想要安装Go的目录为 `$GO_INSTALL_DIR`,后面替换为相应的目录路径。
解压缩`tar.gz`包到安装目录下:`tar zxvf go1.4.2.linux-amd64.tar.gz -C $GO_INSTALL_DIR`
设置PATH`export PATH=$PATH:$GO_INSTALL_DIR/go/bin`
然后执行`go`
![](images/1.1.linux.png?raw=true)
图1.2 Linux系统下安装成功之后执行go显示的信息
如果出现go的Usage信息那么说明go已经安装成功了如果出现该命令不存在那么可以检查一下自己的PATH环境变中是否包含了go的安装目录。
### Windows 安装 ###
访问[Google Code 下载页][downlink]32 位请选择名称中包含 windows-386 的 msi 安装包64 位请选择名称中包含 windows-amd64 的。下载好后运行,不要修改默认安装目录 C:\Go\,若安装到其他位置会导致不能执行自己所编写的 Go 代码。安装完成后默认会在环境变量 Path 后添加 Go 安装目录下的 bin 目录 `C:\Go\bin\`,并添加环境变量 GOROOT值为 Go 安装根目录 `C:\Go\`
**验证是否安装成功**
在运行中输入 `cmd` 打开命令行工具,在提示符下输入 `go`,检查是否能看到 Usage 信息。输入 `cd %GOROOT%`,看是否能进入 Go 安装目录。若都成功,说明安装成功。
不能的话请检查上述环境变量 Path 和 GOROOT 的值。若不存在请卸载后重新安装,存在请重启计算机后重试以上步骤。
## 第三方工具安装
## Use third-party tools
### GVM
gvm是第三方开发的Go多版本管理工具类似ruby里面的rvm工具。使用起来相当的方便安装gvm使用如下命令
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:
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
bash < <(curl -s https://raw.github.com/moovweb/gvm/master/binscripts/gvm-installer)
安装完成后我们就可以安装go了
Then we install Go using the following commands:
gvm install go1.4.2
gvm use go1.4.2
gvm install go1.0.3
gvm use go1.0.3
也可以使用下面的命令省去每次调用gvm use的麻烦
gvm use go1.4.2 --default
执行完上面的命令之后GOPATH、GOROOT等环境变量会自动设置好这样就可以直接使用了。
After the process has finished, you're all set.
### apt-get
Ubuntu是目前使用最多的Linux桌面系统使用`apt-get`命令来管理软件包我们可以通过下面的命令来安装Go为了以后方便应该把 `git` `mercurial` 也安装上:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:gophers/go
sudo apt-get update
sudo apt-get install golang-stable git-core mercurial
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.
### homebrew
homebrew是Mac系统下面目前使用最多的管理软件的工具目前已支持Go可以通过命令直接安装Go为了以后方便应该把 `git` `mercurial` 也安装上:
sudo add-apt-repository ppa:gophers/go
sudo apt-get update
sudo apt-get install golang-stable
brew update && brew upgrade
brew install go
brew install git
brew install mercurial
### Homebrew
Homebrew is a software management tool commonly used in Mac to manage packages. Just type the following commands to install Go.
## links
* [目录](<preface.md>)
* 上一节: [Go环境配置](<01.0.md>)
* 下一节: [GOPATH 与工作空间](<01.2.md>)
brew install go
[downlink]:http://golang.org/dl/ "Go安装包下载"
## Links
- [Directory](preface.md)
- Previous section: [Go environment configuration](01.0.md)
- Next section: [$GOPATH and workspace](01.2.md)