Merge pull request #788 from vCaesar/up10-pr
Update go install and fix set Go env
This commit is contained in:
25
en/01.1.md
25
en/01.1.md
@@ -76,15 +76,15 @@ A 64-bit operating system will show the following:
|
|||||||
|
|
||||||
### Mac
|
### Mac
|
||||||
|
|
||||||
Go to the [download page](https://golang.org/dl/), choose `go1.4.2.darwin-386.pkg` for 32-bit systems and `go1.7.4.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 figure 1.1.
|
Go to the [download page](https://golang.org/dl/), choose `go1.4.2.darwin-386.pkg` (The later version has no 32-bit download.)for 32-bit systems and `go1.8.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 figure 1.1.
|
||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
Go to the [download page](https://golang.org/dl/), choose `go1.7.4.linux-386.tar.gz` for 32-bit systems and `go1.7.4.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.7.4.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.
|
Go to the [download page](https://golang.org/dl/), choose `go1.8.linux-386.tar.gz` for 32-bit systems and `go1.8.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.8.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.
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
Go to the [download page](https://golang.org/dl/), choose `go1.7.4.windows-386.msi` for 32-bit systems and `go1.7.4.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 to the [download page](https://golang.org/dl/), choose `go1.8.windows-386.msi` for 32-bit systems and `go1.8.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.
|
||||||
|
|
||||||
## Use third-party tools
|
## Use third-party tools
|
||||||
|
|
||||||
@@ -96,8 +96,8 @@ GVM is a Go multi-version control tool developed by a third-party, like rvm for
|
|||||||
|
|
||||||
Then we install Go using the following commands:
|
Then we install Go using the following commands:
|
||||||
|
|
||||||
gvm install go1.7.4
|
gvm install go1.8
|
||||||
gvm use go1.7.4
|
gvm use go1.8
|
||||||
|
|
||||||
After the process has finished, you're all set.
|
After the process has finished, you're all set.
|
||||||
|
|
||||||
@@ -112,13 +112,16 @@ Ubuntu is the most popular desktop release version of Linux. It uses `apt-get` t
|
|||||||
###wget
|
###wget
|
||||||
```sh
|
```sh
|
||||||
|
|
||||||
wget https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
|
wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz
|
||||||
sudo tar -xzf go1.7.4.linux-amd64.tar.gz -C /usr/local
|
sudo tar -xzf go1.8.linux-amd64.tar.gz -C /usr/local
|
||||||
export PATH=PATH:/usr/local/go/binexportGOROOT=HOME/go
|
|
||||||
export PATH=PATH:GOROOT/bin
|
|
||||||
export GOPATH=HOME/gowork
|
|
||||||
```
|
|
||||||
|
|
||||||
|
# Go environment
|
||||||
|
export GOROOT=/usr/local/go
|
||||||
|
export GOBIN=$GOROOT/bin
|
||||||
|
export PATH=$PATH:$GOBIN
|
||||||
|
export GOPATH=HOME/gopath
|
||||||
|
```
|
||||||
|
Starting from go 1.8,The GOPATH environment variable now has a default value if it is unset. It defaults to $HOME/go on Unix and %USERPROFILE%/go on Windows.
|
||||||
### Homebrew
|
### Homebrew
|
||||||
|
|
||||||
Homebrew is a software management tool commonly used in Mac to manage packages. Just type the following commands to install Go.
|
Homebrew is a software management tool commonly used in Mac to manage packages. Just type the following commands to install Go.
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
Go takes a unique approach to manage the code files with the introduction of a `$GOPATH` directory which contains all the go code in the machine. Note that this is different from the `$GOROOT` environment variable which states where go is installed on the machine. We have to define the $GOPATH variable before using the language, in *nix systems there is a file called `.bashrc` we need to append the below export statement to the file. The concept behind gopath is a novel one, where we can link to any go code at any instant of time without ambiguity.
|
Go takes a unique approach to manage the code files with the introduction of a `$GOPATH` directory which contains all the go code in the machine. Note that this is different from the `$GOROOT` environment variable which states where go is installed on the machine. We have to define the $GOPATH variable before using the language, in *nix systems there is a file called `.bashrc` we need to append the below export statement to the file. The concept behind gopath is a novel one, where we can link to any go code at any instant of time without ambiguity.
|
||||||
|
|
||||||
|
Starting from go 1.8,The GOPATH environment variable now has a default value if it is unset. It defaults to $HOME/go on Unix and %USERPROFILE%/go on Windows.
|
||||||
|
|
||||||
In Unix-like systems, the variable should be used like this:
|
In Unix-like systems, the variable should be used like this:
|
||||||
|
|
||||||
export GOPATH=/home/apple/mygo
|
export GOPATH=/home/apple/mygo
|
||||||
|
|||||||
42
zh/01.1.md
42
zh/01.1.md
@@ -46,6 +46,7 @@ Go 1.5彻底移除C代码,Runtime、Compiler、Linker均由Go编写,实现自
|
|||||||
|
|
||||||
如果出现Go的Usage信息,那么说明Go已经安装成功了;如果出现该命令不存在,那么可以检查一下自己的PATH环境变中是否包含了Go的安装目录。
|
如果出现Go的Usage信息,那么说明Go已经安装成功了;如果出现该命令不存在,那么可以检查一下自己的PATH环境变中是否包含了Go的安装目录。
|
||||||
|
|
||||||
|
从go 1.8开始,GOPATH环境变量现在有一个默认值,如果它没有被设置。 它在Unix上默认为$HOME/go,在Windows上默认为%USERPROFILE%/go。
|
||||||
> 关于上面的GOPATH将在下面小节详细讲解
|
> 关于上面的GOPATH将在下面小节详细讲解
|
||||||
|
|
||||||
## Go标准包安装
|
## Go标准包安装
|
||||||
@@ -78,7 +79,7 @@ Linux系统用户可通过在Terminal中执行命令`arch`(即`uname -m`)来查
|
|||||||
|
|
||||||
### Mac 安装
|
### Mac 安装
|
||||||
|
|
||||||
访问[下载地址][downlink],32位系统下载go1.4.2.darwin-386-osx10.8.pkg(最新版已无32位下载),64位系统下载go1.7.4.darwin-amd64.pkg,双击下载文件,一路默认安装点击下一步,这个时候go已经安装到你的系统中,默认已经在PATH中增加了相应的`~/go/bin`,这个时候打开终端,输入`go`
|
访问[下载地址][downlink],32位系统下载go1.4.2.darwin-386-osx10.8.pkg(更新版已无32位下载),64位系统下载go1.8.darwin-amd64.pkg,双击下载文件,一路默认安装点击下一步,这个时候go已经安装到你的系统中,默认已经在PATH中增加了相应的`~/go/bin`,这个时候打开终端,输入`go`
|
||||||
|
|
||||||
看到类似上面源码安装成功的图片说明已经安装成功
|
看到类似上面源码安装成功的图片说明已经安装成功
|
||||||
|
|
||||||
@@ -86,11 +87,11 @@ Linux系统用户可通过在Terminal中执行命令`arch`(即`uname -m`)来查
|
|||||||
|
|
||||||
### Linux 安装
|
### Linux 安装
|
||||||
|
|
||||||
访问[下载地址][downlink],32位系统下载go1.7.4.linux-386.tar.gz,64位系统下载go1.7.4.linux-amd64.tar.gz,
|
访问[下载地址][downlink],32位系统下载go1.8.linux-386.tar.gz,64位系统下载go1.8.linux-amd64.tar.gz,
|
||||||
|
|
||||||
假定你想要安装Go的目录为 `$GO_INSTALL_DIR`,后面替换为相应的目录路径。
|
假定你想要安装Go的目录为 `$GO_INSTALL_DIR`,后面替换为相应的目录路径。
|
||||||
|
|
||||||
解压缩`tar.gz`包到安装目录下:`tar zxvf go1.7.4.linux-amd64.tar.gz -C $GO_INSTALL_DIR`。
|
解压缩`tar.gz`包到安装目录下:`tar zxvf go1.8.linux-amd64.tar.gz -C $GO_INSTALL_DIR`。
|
||||||
|
|
||||||
设置PATH,`export PATH=$PATH:$GO_INSTALL_DIR/go/bin`
|
设置PATH,`export PATH=$PATH:$GO_INSTALL_DIR/go/bin`
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ Linux系统用户可通过在Terminal中执行命令`arch`(即`uname -m`)来查
|
|||||||
|
|
||||||
### Windows 安装 ###
|
### Windows 安装 ###
|
||||||
|
|
||||||
访问[Google Code 下载页][downlink],32 位请选择名称中包含 windows-386 的 msi 安装包,64 位请选择名称中包含 windows-amd64 的。下载好后运行,不要修改默认安装目录 C:\Go\,若安装到其他位置会导致不能执行自己所编写的 Go 代码。安装完成后默认会在环境变量 Path 后添加 Go 安装目录下的 bin 目录 `C:\Go\bin\`,并添加环境变量 GOROOT,值为 Go 安装根目录 `C:\Go\` 。
|
访问[Golang 下载页][downlink],32 位请选择名称中包含 windows-386 的 msi 安装包,64 位请选择名称中包含 windows-amd64 的。下载好后运行,不要修改默认安装目录 C:\Go\,若安装到其他位置会导致不能执行自己所编写的 Go 代码。安装完成后默认会在环境变量 Path 后添加 Go 安装目录下的 bin 目录 `C:\Go\bin\`,并添加环境变量 GOROOT,值为 Go 安装根目录 `C:\Go\` 。
|
||||||
|
|
||||||
**验证是否安装成功**
|
**验证是否安装成功**
|
||||||
|
|
||||||
@@ -124,11 +125,11 @@ gvm是第三方开发的Go多版本管理工具,类似ruby里面的rvm工具
|
|||||||
安装完成后我们就可以安装go了:
|
安装完成后我们就可以安装go了:
|
||||||
```sh
|
```sh
|
||||||
|
|
||||||
gvm install go1.7.4
|
gvm install go1.8
|
||||||
gvm use go1.7.4
|
gvm use go1.8
|
||||||
```
|
```
|
||||||
也可以使用下面的命令,省去每次调用gvm use的麻烦:
|
也可以使用下面的命令,省去每次调用gvm use的麻烦:
|
||||||
gvm use go1.7.4 --default
|
gvm use go1.8 --default
|
||||||
|
|
||||||
执行完上面的命令之后GOPATH、GOROOT等环境变量会自动设置好,这样就可以直接使用了。
|
执行完上面的命令之后GOPATH、GOROOT等环境变量会自动设置好,这样就可以直接使用了。
|
||||||
|
|
||||||
@@ -144,11 +145,28 @@ Ubuntu是目前使用最多的Linux桌面系统,使用`apt-get`命令来管理
|
|||||||
###wget
|
###wget
|
||||||
```sh
|
```sh
|
||||||
|
|
||||||
wget https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
|
wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz
|
||||||
sudo tar -xzf go1.7.4.linux-amd64.tar.gz -C /usr/local
|
sudo tar -xzf go1.8.linux-amd64.tar.gz -C /usr/local
|
||||||
export PATH=PATH:/usr/local/go/binexportGOROOT=HOME/go
|
```
|
||||||
export PATH=PATH:GOROOT/bin
|
|
||||||
export GOPATH=HOME/gowork
|
配置环境变量:
|
||||||
|
```sh
|
||||||
|
|
||||||
|
export GOROOT=/usr/local/go
|
||||||
|
export GOBIN=$GOROOT/bin
|
||||||
|
export PATH=$PATH:$GOBIN
|
||||||
|
export GOPATH=HOME/gopath (可选设置)
|
||||||
|
```
|
||||||
|
或者使用:
|
||||||
|
```sh
|
||||||
|
sudo vim /etc/profile
|
||||||
|
```
|
||||||
|
并添加下面的内容:
|
||||||
|
```sh
|
||||||
|
export GOROOT=/usr/local/go
|
||||||
|
export GOBIN=$GOROOT/bin
|
||||||
|
export PATH=$PATH:$GOBIN
|
||||||
|
export GOPATH=HOME/gopath (可选设置)
|
||||||
```
|
```
|
||||||
|
|
||||||
### homebrew
|
### homebrew
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
# 1.2 GOPATH与工作空间
|
# 1.2 GOPATH与工作空间
|
||||||
|
|
||||||
前面我们在安装Go的时候看到需要设置GOPATH变量,Go从1.1版本开始必须设置这个变量,而且不能和Go的安装目录一样,这个目录用来存放Go源码,Go的可运行文件,以及相应的编译之后的包文件。所以这个目录下面有三个子目录:src、bin、pkg
|
前面我们在安装Go的时候看到需要设置GOPATH变量,Go从1.1版本到1.7必须设置这个变量,而且不能和Go的安装目录一样,这个目录用来存放Go源码,Go的可运行文件,以及相应的编译之后的包文件。所以这个目录下面有三个子目录:src、bin、pkg
|
||||||
|
|
||||||
|
从go 1.8开始,GOPATH环境变量现在有一个默认值,如果它没有被设置。 它在Unix上默认为$HOME/go,在Windows上默认为%USERPROFILE%/go。
|
||||||
## GOPATH设置
|
## GOPATH设置
|
||||||
go 命令依赖一个重要的环境变量:$GOPATH
|
go 命令依赖一个重要的环境变量:$GOPATH
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user