ubuntu18.04 源码安装 go-lang 居然这么麻烦!

in mini.topia6 years ago (edited)

因为要装一个开源软件,需要ubuntu下的go语言开发环境。

用这个开源软件,是为了隐私和安全,所以自然要对其使用源码编译方式。

这个软件需要最新版本的go,因此不得不手工源码安装go-lang。因为ubuntu默认安装的go并不是最新版本。

下面体验以下源码安装go的过程。

清除旧版本文件:

$ sudo apt-get remove golang-go
$ sudo apt autoremove 
$ cd /usr/lib
$ sudo rm -rf go go-1.10

安装环境:

$ sudo apt-get install bison gawk gcc libc6-dev make mercurial

下载源码:

$ hg clone -r release https://go.googlecode.com/hg/ /usr/lib/go

如果失败,可以直接下载源码压缩包(去官网查看最新版链接):https://studygolang.com/dl

$ wget https://studygolang.com/dl/golang/go1.14.src.tar.gz
$ sudo tar -zxvf go1.14.src.tar.gz  -C /usr/lib

添加go的工作目录:

$ mkdir ~/go-1.14
$ cd ~/go-1.14
$ mkdir bin  pkg  src

添加环境变量:$ sudo vi ~/.profile

# for go-lang
export GOPATH=~/go-1.14
export GOROOT=/usr/lib/go
export GOARCH=386
export GOOS=linux
export GOTOOLS=$GOROOT/pkg/tool
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

进入源码目录:$ cd /usr/lib/go/src
执行源码安装go: $ ./all.bash
错误提示:

/usr/lib/go/src$ ./all.bash 
./make.bash: 行 165: /home/userxxx/go1.4/bin/go: 没有那个文件或目录
Building Go cmd/dist using /home/userxxx/go1.4. ()
ERROR: Cannot find /home/userxxx/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.

详细看了 all.bash,调用了目录下的 make.bash,脚本中提及,需要安装一个旧版本的go:

$ sudo apt-get install golang-go
$ go version

版本提示:

go version go1.10.4 linux/amd64

重新执行源码安装go: $ ./all.bash
进入正常安装程序。

安装后,删除旧版本的go:$ sudo apt-get remove golang-go
更新环境变量:$ source ~/.profile
查看版本:$ go version
go版本已经为最新的1.14:

go version go1.14 linux/amd64
Sort:  

Congratulations @dappcoder! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published more than 50 posts. Your next target is to reach 60 posts.
You published a post every day of the week

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Vote for @Steemitboard as a witness to get one more award and increased upvotes!