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安装完毕;
最后更新于 2020-03-12 13:38:48 并被添加「编译 go」标签,已有 1780 位童鞋阅读过。
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处
此处评论已关闭