diff --git a/en/01.1.md b/en/01.1.md index fcdbec60..023b989c 100644 --- a/en/01.1.md +++ b/en/01.1.md @@ -76,15 +76,15 @@ A 64-bit operating system will show the following: ### 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 -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 -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 @@ -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: - gvm install go1.7.4 - gvm use go1.7.4 + gvm install go1.8 + gvm use go1.8 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 ```sh -wget https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz -sudo tar -xzf go1.7.4.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 -``` +wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz +sudo tar -xzf go1.8.linux-amd64.tar.gz -C /usr/local +# 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 is a software management tool commonly used in Mac to manage packages. Just type the following commands to install Go. diff --git a/en/01.2.md b/en/01.2.md index e927e21e..d1260864 100644 --- a/en/01.2.md +++ b/en/01.2.md @@ -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. +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: export GOPATH=/home/apple/mygo diff --git a/zh/01.1.md b/zh/01.1.md index e8c1c1f5..053fc0a6 100644 --- a/zh/01.1.md +++ b/zh/01.1.md @@ -46,6 +46,7 @@ Go 1.5彻底移除C代码,Runtime、Compiler、Linker均由Go编写,实现自 如果出现Go的Usage信息,那么说明Go已经安装成功了;如果出现该命令不存在,那么可以检查一下自己的PATH环境变中是否包含了Go的安装目录。 +从go 1.8开始,GOPATH环境变量现在有一个默认值,如果它没有被设置。 它在Unix上默认为$HOME/go,在Windows上默认为%USERPROFILE%/go。 > 关于上面的GOPATH将在下面小节详细讲解 ## Go标准包安装 @@ -78,7 +79,7 @@ Linux系统用户可通过在Terminal中执行命令`arch`(即`uname -m`)来查 ### 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 安装 -访问[下载地址][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`,后面替换为相应的目录路径。 -解压缩`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` @@ -104,7 +105,7 @@ Linux系统用户可通过在Terminal中执行命令`arch`(即`uname -m`)来查 ### 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了: ```sh - gvm install go1.7.4 - gvm use go1.7.4 + gvm install go1.8 + gvm use go1.8 ``` 也可以使用下面的命令,省去每次调用gvm use的麻烦: - gvm use go1.7.4 --default + gvm use go1.8 --default 执行完上面的命令之后GOPATH、GOROOT等环境变量会自动设置好,这样就可以直接使用了。 @@ -144,11 +145,28 @@ Ubuntu是目前使用最多的Linux桌面系统,使用`apt-get`命令来管理 ###wget ```sh -wget https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz -sudo tar -xzf go1.7.4.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 +wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz +sudo tar -xzf go1.8.linux-amd64.tar.gz -C /usr/local +``` + +配置环境变量: +```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 diff --git a/zh/01.2.md b/zh/01.2.md index 5c708666..abe528bf 100644 --- a/zh/01.2.md +++ b/zh/01.2.md @@ -1,7 +1,8 @@ # 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设置 go 命令依赖一个重要的环境变量:$GOPATH