create account

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

View this thread on: hive.blogpeakd.comecency.com
· @dappcoder · (edited)
$5.79
ubuntu18.04 源码安装 go-lang 居然这么麻烦!
因为要装一个开源软件,需要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
```
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 66 others
properties (23)
authordappcoder
permlinkubuntu18-04-go-lang
categoryhive-132971
json_metadata{"tags":["cn","mini","jjm","cn-reader","esteem","steemleo","zzan"],"links":["https://studygolang.com/dl"],"app":"steemit/0.2","format":"markdown"}
created2020-03-15 09:55:39
last_update2020-03-15 10:15:00
depth0
children1
last_payout2020-03-22 09:55:39
cashout_time1969-12-31 23:59:59
total_payout_value2.912 HBD
curator_payout_value2.875 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,521
author_reputation9,480,331,507,174
root_title"ubuntu18.04 源码安装 go-lang 居然这么麻烦!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,370,923
net_rshares14,949,432,072,346
author_curate_reward""
vote details (130)
@steemitboard ·
Congratulations @dappcoder! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://steemitimages.com/60x70/http://steemitboard.com/@dappcoder/posts.png?202003152357"></td><td>You published more than 50 posts. Your next target is to reach 60 posts.</td></tr>
<tr><td><img src="https://steemitimages.com/60x60/http://steemitboard.com/img/notifications/postallweek.png"></td><td>You published a post every day of the week</td></tr>
</table>

<sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@dappcoder) and compare to others on the [Steem Ranking](https://steemitboard.com/ranking/index.php?name=dappcoder)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>


To support your work, I also upvoted your post!


###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-dappcoder-20200316t084217000z
categoryhive-132971
json_metadata{"image":["https://steemitboard.com/img/notify.png"]}
created2020-03-16 08:42:18
last_update2020-03-16 08:42:18
depth1
children0
last_payout2020-03-23 08:42:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,062
author_reputation38,975,615,169,260
root_title"ubuntu18.04 源码安装 go-lang 居然这么麻烦!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,400,345
net_rshares0