背景
最近刷到Go1.18已经开始支持泛型了,想尝尝鲜,看下使用起来是否好用,毕竟这玩意提了好久。自己Mac电脑上装的是Go1.16版本的,不想用docker再配一个环境(没错,就是这么矫情😂),所以找找看是否有比较好的升级方法。
果然群众的力量是强大的,找到了一个Go版本管理的脚本update-golang, 可以轻松地拉取和安装新的 Go 版本,基本不会对系统配置做什么修改, 同时提供 remove 方法, 一键卸载 Go 环境。
更新环境
使用步骤很简单,下载,然后执行,直接可以更新到最新版本。
1
2
3
|
git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh
|
注意事项
作者建议我们在使用之前,执行以下命令,校验一下脚本没有被串改过
1
2
3
|
$ wget -qO hash.txt https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh.sha256
$ sha256sum -c hash.txt
update-golang.sh: OK
|
总体使用例子
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
lab@ubu1:~$ go
The program 'go' can be found in the following packages:
* golang-go
* gccgo-go
Try: sudo apt install <selected package>
lab@ubu1:~$
lab@ubu1:~$ git clone https://github.com/udhos/update-golang
Cloning into 'update-golang'...
remote: Counting objects: 481, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 481 (delta 4), reused 9 (delta 2), pack-reused 468
Receiving objects: 100% (481/481), 70.22 KiB | 125.00 KiB/s, done.
Resolving deltas: 100% (248/248), done.
lab@ubu1:~$
lab@ubu1:~$ cd update-golang
lab@ubu1:~/update-golang$ sudo ./update-golang.sh
update-golang.sh: version 0.15
update-golang.sh: find_latest: found last release: 1.10.2
update-golang.sh: user: uid=0(root) gid=0(root) groups=0(root)
update-golang.sh: RELEASE_LIST=https://golang.org/doc/devel/release.html
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.10.2
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: will install golang go1.10.2.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.10.2.linux-amd64.tar.gz is remote
update-golang.sh: no need to download - file cached: /usr/local/go1.10.2.linux-amd64.tar.gz
update-golang.sh: remove_old_link: not found symlink for old install
update-golang.sh: untar: tar -x -f /usr/local/go1.10.2.linux-amd64.tar.gz
update-golang.sh: path: removing old settings from: /etc/profile.d/golang_path.sh
update-golang.sh: path: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: path: issuing /home/lab/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: golang go1.10.2.linux-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: go version go1.10.2 linux/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmpv1bX1rQN.go
update-golang.sh: hello, world
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmpv1bX1rQN.go: SUCCESS
update-golang.sh: cleanup: /tmp/tmp.tcNY25eXNl
lab@ubu1:~/update-golang$
|
指定更新版本
看了下说明文档,保守起见,我是直接指定参数,选择1.18的版本。相关版本列表可以点此查看,可能需要翻墙
1
|
sudo RELEASE=1.18 ./update-golang.sh
|
一键卸载 Go 环境
1
|
$ sudo ./update-golang.sh remove
|