準(zhǔn)備工作
- 一個(gè)“干凈”的系統(tǒng)是必須的制市,本次操作在阿里云上完成抬旺。
[root@snails ~]# hostnamectl set-hostname snails
[root@snails ~]# hostnamectl
Static hostname: snails
Icon name: computer-vm
Chassis: vm
Machine ID: 7d26c16f116042a684ea498c9e2c240f
Boot ID: e567275688e84ce3b72a11794dc8ac9b
Virtualization: xen
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
實(shí)踐過(guò)程
配置yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
安裝git弊予、gcc祥楣、vim
yum -y install git gcc vim
[root@snails ~]# git --version
git version 1.8.3.1
[root@snails src]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright ? 2015 Free Software Foundation, Inc.
本程序是自由軟件;請(qǐng)參看源代碼的版權(quán)聲明汉柒。本軟件沒(méi)有任何擔(dān)保误褪;
包括沒(méi)有適銷性和某一專用目的下的適用性擔(dān)保。
下載go 1.4分支
[root@snails ~]#git clone -b release-branch.go1.4 https://github.com/golang/go.git go
編譯并配置環(huán)境變量
- 編譯
[root@snails ~]#cd go/src
[root@snails ~]#./all.bash
ALL TESTS PASSED
Installed Go for linux/amd64 in /root/go
Installed commands in /root/go/bin
*** You need to add /root/go/bin to your PATH.
- 配置環(huán)境變量
[root@snails ~]#cd ~ && mkdir -p golang/{src,pkg,bin}
[root@snails ~]#vi /etc/profile
export GOPATH=$HOME/golang
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin
[root@snails ~]# source /etc/profile
[root@snails ~]# go version
go version go1.4.3 linux/amd64
更新go版本再次編譯
- 更新go版本
[root@snails ~]# mv go go-bootstrap
[root@snails ~]# git clone https://github.com/golang/go.git
[root@snails ~]# cd go
- 再次編譯
[root@snails go]# vi /etc/profile
export GOROOT_BOOTSTRAP=$HOME/go-bootstrap
[root@snails go]# source /etc/profile
[root@snails go]# cd src/
[root@snails src]# ./clean.bash(可選)
[root@snails src]# ./all.bash
./clean.bash 是針對(duì)多次編譯的情況下碾褂,先清除上一次編譯結(jié)果兽间。比如由1.7編譯后,再升級(jí)到1.7.1版本正塌;默認(rèn)情況下可以不用嘀略。
實(shí)踐驗(yàn)證
[root@snails src]# go version
go version devel +d872201 Thu Jul 7 04:06:52 2016 +0000 linux/amd64