准备工作
- 一个“干净”的系统是必须的,本次操作在阿里云上完成。
[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
实践过程
配置yum源
CentOS 7配置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. 本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保; 包括没有适销性和某一专用目的下的适用性担保。
下载go 1.4分支
[root@snails ~]#git clone -b release-branch.go1.4 https://github.com/golang/go.git go
编译并配置环境变量
- 编译
[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.
- 配置环境变量
[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 是针对多次编译的情况下,先清除上一次编译结果。比如由1.7编译后,再升级到1.7.1版本;默认情况下可以不用。
实践验证
[root@snails src]# go version
go version devel +d872201 Thu Jul 7 04:06:52 2016 +0000 linux/amd64
有疑问加站长微信联系(非本文作者)