CentOS7.3编译安装go1.8.1
go1.8.1下载地址https://golang.org/dl/,这里下载go1.8.1.src.tar.gz和go1.4.3.src.tar.gz,下来以后算下md5哈希和官网比对下,以免被加盐,国内可以用这个地址下载:https://golang.google.cn/dl/
go1.4以上版本安装的时候需先安装下1.4;要么会报错:
##### Building Go bootstrap tool.
cmd/dist
ERROR: Cannot find /root/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
开始安装:
yum install gcc glibc-devel -y
tar -C /root/ -xvf go1.4.3.src.tar.gz
mv /root/go/ /root/go1.4
cd /root/go1.4/src
CGO_ENABLED=0 ./make.bash
约1分钟左右安装完成,设置下环境变量并重新加载
echo "export PATH=$PATH:/root/go1.4/bin" >> /etc/profile
echo "export GOROOT=/root/go1.4" >> /etc/profile
source /etc/profile
使用go version查看版本已经是go1.4.3了
开始安装go1.8.1
tar -C /usr/local/ -xvf go1.8.1.src.tar.gz
cd /usr/local/go/src/
./all.bash
安装完成以后,清除掉之前添加的/etc/profile里面的环境变量信息,增加如下配置
echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export GOPATH=/usr/local/go-projects" >> /etc/profile
source /etc/profile
重新加载配置
source /etc/profile
查看版本go version
已经是1.8.1了
创建go的hello world程序:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
保存为hello.go
直接运行 go run hello.go
返回hello,world!
至此,go1.8.1安装完毕;
请问,安装1.4的时候报错怎么办:
--- FAIL: TestParseInLocation (0.08s)
format_test.go:202: ParseInLocation(Feb 01 2013 AST, Baghdad) = 2013-02-01 00:00:00 +0000 AST, want 2013-02-01 00:00:00 +0300 +03
--- FAIL: TestLoadFixed (0.07s)
time_test.go:929: Now().In(loc).Zone() = "-01", -3600, want "GMT+1", -3600
照着上面安装步骤进行,可能是少安装了包·
你的系统版本是那个?