3

Linux下go1.8安装方法

 2 years ago
source link: https://dawnki.github.io/2017/08/12/Linux%E4%B8%8Bgo1-8%E5%AE%89%E8%A3%85%E6%96%B9%E6%B3%95/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux下go1.8安装方法

2017-08-12

之前迷上了神奇的Go语言,就在windows上装上了Go1.8,挺顺风顺水的,不过最近换上了Linux时,编译安装就炸了,各种报错。今天就留个记录,备个份!

编译安装Go1.8的主体思路:

  1. github中clone下来
  2. 确保linux系统安装较新的libc,gcc(apt,yum随便搞上)
  3. 切换库分支至1.4(刚clone下来的库),去到src目录,执行all.bash
  4. 把编译安装完的1.4目录cp到/root/,并更名为go1.4
  5. 将刚刚的编译安装的仓库恢复原状(git clean -dfx),在切换到1.8,同样刚刚的操作,执行all.bash,安装1.8
  6. 然后1.8安装完后,配置profile

1.由于Go1.8的安装需要go1.4的二进制,所以,如果没安装go1.4的小伙伴,直接安装1.8估计会这样

Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.

这个GOROOT_BOOTSTRAP地址默认在/root/go1.4(~/go1.4)

2.用all.bash安装1.4时炸了

# cmd/pprof
.../go1.4/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic?
.../go1.4/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic?
runtime/cgo(.text): unexpected relocation type 298
runtime/cgo(.text): unexpected relocation type 298

拿去不用谢我.jpg

所以解决方案是

$ cd ~/go1.4/src
$ CGO_ENABLED=0 ./make.bash

导致的原因是:CGO_ENABLED: Controls cgo usage during the build. Set it to 1 to include all cgo related files, .c and .go file with “cgo” build directive, in the build. Set it to 0 to ignore them.在构建过程中控制cgo的使用。当设置为1,在构建时,会包含所有cgo相关的文件,如带有”cgo”编译指令的.c和.go文件。当设置为0,则忽略它们(即禁用CGO)

3.在顺利的安装完1.4后再安装1.8,应该也没问题了,最后设置一下环境变量

vim /ect/profile

在里面加上:

# Golang Env
export PATH=$PATH:/home/xx/go/bin //xx根据实际情况填写
export GOPATH=/home/xx/go-projects //xx根据实际情况填写

然后重启电脑,执行

go version

显示到版本号的话就可以愉快的玩耍了!

虽然安装的历程有点坎坷,不过看在go编程这么奇葩有趣的份上,忍了吧!O(∩_∩)O哈哈~

中国网络环境下源码编译安装Go1.6

最后更新时间:2017-08-12 12:28:53

对本文内容有任何意见,建议,疑问etc,均可通过邮箱联系我,逗比博主尽最大努力回复O(∩_∩)O,如需转载(tan90°,不存在的(°Д°)),注明出处即可!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK