美文网首页
Linux系统编译安装Go1.9.2

Linux系统编译安装Go1.9.2

作者: 田佳伟 | 来源:发表于2017-12-29 15:08 被阅读0次
  1. 下载
    下载链接:https://www.golangtc.com/download
wget https://storage.googleapis.com/golang/go<VERSION>.src.tar.gz
tar -zxvf go<VERSION>.src.tar.gz
sudo mv go /user/local/

默认放到/user/local/目录下,然后进行安装

cd /usr/local/go/src
./all.bash

执行之后发现报错

vagrant@homestead:/usr/local/go/src$ ./all.bash 
##### Building Go bootstrap tool.
cmd/dist
ERROR: Cannot find /home/vagrant/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.

为什么会报错找不到go1.4呢?不是还没安装呢吗?原来编译GO 1.6版本以上的需要依赖GO 1.4版本的二进制
于是要先编译安装1.4版本

  • 首先要确定是否安装了 gcc和glibc-devel
$ cd ~/
$ git clone git@github.com:golang/go.git
$ cd go/
$ git checkout -b 1.4 go1.4  //将远程的go1.4分支checkout
$ cd ~/go/src
$ sudo ./all.bash
$ cp -rf ~/go/ ~/go1.4

编译过程中遇到了报错

# cmd/pprof
/home/vagrant/go/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic?
/home/vagrant/go/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

解决方案:

$ cd ~/go1.4/src
$ sudo 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)

编译完了go1.4版本,然后就可以编译v1.9.2了

$ cd ~/go
$ git clean -dfx //删除当前目录下所有没有track过的文件. 不管他是否是.gitignore文件里面指定的文件夹和文件
$ git checkout -b 1.9.2 go1.9.2
$ cd ~/go/src
$ sudo ./all.bash
  1. 配置环境变量
    在 ~/.profile文件末尾追加如下命令,在打开一个回话的时候,会自动执行~/.profile,配置环境变量
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/usr/local/go/production

参考:
在中国网络环境下从源代码安装Go1.6到CentOS 7

相关文章

  • Linux系统编译安装Go1.9.2

    下载下载链接:https://www.golangtc.com/download 默认放到/user/local/...

  • Mesos 安装

    安装 系统要求: 64位的linux或mac系统 安装: 1.源码编译安装(centos 7.0) 编译环境准备 ...

  • 一、Mysql安装

    环境:Linux系统 mysql编译安装 关闭防火墙和selinux 1、编译安装mysql5.7 1、清理安装环...

  • LNMP环境配置

    Linux 系统环境:CentOs 7 Nginx 安装 一.源码安装(未实践) 1)新系统要安装编译工具$ yu...

  • Lua 环境安装

    Linux 系统上安装 Linux & Mac上安装 Lua 安装非常简单,只需要下载源码包并在终端解压编译即可,...

  • Redis初探

    安装 Linux系统,在官网下载Redis 源码,按照README中的描述编译安装。 Windows系统,Gith...

  • Redis 安装

    本文介绍基于 Linux 系统的 Redis 编译安装 一、安装 1、安装 gcc 环境 2、下载 redis 安...

  • PMDK编译安装

    PMDK编译安装 系统环境:CentOS 7 依赖包 Linux: autoconfyum install aut...

  • 如何编译和更换Linux系统内核

    如何编译和更换Linux系统内核 step0 — 完成编译和安装Linux需要的基本条件 内核源代码从http:/...

  • golang Linux环境搭建

    1、查看linux系统版本 2、源码编译安装gogo语言的安装地址:https://golang.google.c...

网友评论

      本文标题:Linux系统编译安装Go1.9.2

      本文链接:https://www.haomeiwen.com/subject/mvnmgxtx.html