我的环境时 thinkpad s430, ubuntu 16.04, 64位
得益于论坛里各位前辈的指点, 现将安装流程记录如下方便大家方便自己
## 软件需求
需要gcc, make, git 等一些常用的开发软件
```shell
apt-get install bison ed gawk gcc libc6-dev make git
```
## 环境变量
可以在/etc/profile, ~/.bashrc中添加go使用的环境变量
```bash
export GOROOT=/usr/local/go
export GOPATH=$HOME/project/go
export GOBIN=$HOME/bin
export GOROOT_BOOTSTRAP=/usr/local/go1.4
export PATH=$PATH:$GOROOT/bin:$GOBIN
```
## 拉取源码
```shell
git clone https://github.com/golang/go.git
```
## 准备编译工具
1.4 以后的go 使用go 构建自己的编译工具(boot_strap), 且为必要条件,所以我们用1.4的版本先行编译go,再用该go编译最新的源码
```shell
git fetch origin release-branch.go1.4:release-branch.go1.4
git checkout release-branch.go1.4
cd src ; ./make.bash
mv /root/bin/go /usr/local/go1.4/bin/
```
为什么有最后一步的mv操作?
- 查看make.bash就不难查到,它的编译环境已经限死在/usr/local/go1.4/bin/
## 开始编译最新的版本吧
我们需要切到最新的发布版本分支上,编译我们需要的版本(此时go最新的分支为1.9)
```shell
git fetch origin release-branch.go1.9:release-branch.go1.9
git checkout release-branch.go1.9
cd src ; ./make.bash
```
## 完整的操作shell
```shell
$ su root
$ apt-get install gcc vim make git
$ echo "export GOROOT=/usr/local/go" >> /etc/profile
$ echo "export GOPATH=$HOME/project/go" >> /etc/profile
$ echo "export GOBIN=$HOME/bin" >> /etc/profile
$ echo "export GOROOT_BOOTSTRAP=/usr/local/go1.4" >> /etc/profile
$ echo "export PATH=$PATH:$GOROOT/bin:$GOBIN" >> /etc/profile
$ source /etc/profile
$ cd /usr/local/
$ git clone https://github.com/golang/go.git
$ cp go go1.4 -rf
$ cd go1.4
$ git fetch origin release-branch.go1.4:release-branch.go1.4
$ git checkout release-branch.go1.4
$ cd src ; ./make.bash
$ mv /root/bin/go /usr/local/go1.4/bin/
$ cd /usr/local/go
$ git fetch origin release-branch.go1.9:release-branch.go1.9
$ git checkout release-branch.go1.9
$ cd src ; ./make.bash
$ go version
```
看到以下输出时,恭喜你!
```shell
go version go1.9.5 linux/amd64
```
有疑问加站长微信联系(非本文作者))