Closed englianhu closed 2 years ago
## 方案 01
echo "export PATH=/usr/lib/go/bin:${PATH}" | sudo tee /etc/profile.d/go.sh
source /etc/profile.d/go.sh
go version
## 方案 02
echo "export PATH=/usr/lib/go/bin:${PATH}" | sudo tee -a $HOME/.profile source
source $HOME/.profile
go version
:~$ cd /home/englianhu/文档/GitHub/update-golang/
:~/文档/GitHub/update-golang$ sudo ./update-golang.sh
update-golang.sh: version 0.26
update-golang.sh: find_latest: found last release: 1.19
update-golang.sh: user: uid=0(root) gid=0(root) 组=0(root)
update-golang.sh:
update-golang.sh: RELEASE_LIST=https://go.dev/dl/
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.19
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: FORCE_IPV4= ;# set FORCE_IPV4=-4 to force IPv4
update-golang.sh: CONNECT_TIMEOUT=5
update-golang.sh: SKIP_WGET= ;# set SKIP_WGET=1 to skip wget
update-golang.sh:
update-golang.sh:
update-golang.sh: WARNING
update-golang.sh: WARNING: golang-go is installed, you should remove it: sudo apt remove golang-go
update-golang.sh: WARNING
update-golang.sh:
update-golang.sh: will install golang go1.19.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.19.linux-amd64.tar.gz is remote
update-golang.sh: download: wget --connect-timeout 5 -O /usr/local/go1.19.linux-amd64.tar.gz https://storage.googleapis.com/golang/go1.19.linux-amd64.tar.gz
--2022-09-04 00:30:08-- https://storage.googleapis.com/golang/go1.19.linux-amd64.tar.gz
正在解析主机 storage.googleapis.com (storage.googleapis.com)... 2a00:1450:400c:c08::80, 2a00:1450:400c:c1b::80, 2a00:1450:400c:c06::80, ...
正在连接 storage.googleapis.com (storage.googleapis.com)|2a00:1450:400c:c08::80|:443... 失败:连接超时。
正在连接 storage.googleapis.com (storage.googleapis.com)|2a00:1450:400c:c1b::80|:443... 失败:连接超时。
正在连接 storage.googleapis.com (storage.googleapis.com)|2a00:1450:400c:c06::80|:443... 失败:连接超时。
正在连接 storage.googleapis.com (storage.googleapis.com)|2a00:1450:400c:c07::80|:443... 失败:连接超时。
正在连接 storage.googleapis.com (storage.googleapis.com)|66.102.1.128|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:148796421 (142M) [application/x-gzip]
正在保存至: “/usr/local/go1.19.linux-amd64.tar.gz”
/usr/local/go1.19. 100%[==============>] 141.90M 8.14MB/s 用时 20s
2022-09-04 00:30:50 (7.26 MB/s) - 已保存 “/usr/local/go1.19.linux-amd64.tar.gz” [148796421/148796421])
update-golang.sh: remove_old_link: found symlink for old install: /usr/local/go1.19.linux-amd64
update-golang.sh: untar: rm_dir /usr/local/go1.19.linux-amd64
update-golang.sh: untar: tar -x -f /usr/local/go1.19.linux-amd64.tar.gz
update-golang.sh: profile_path_add: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: profile_path_add: issuing $HOME/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: golang go1.19.linux-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: unsudo: running_as_root:englianhu: /usr/local/go/bin/go version
update-golang.sh: go version go1.19 linux/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: unsudo: running_as_root:englianhu: mktemp -t hello-tmpXXXXXXXX
update-golang.sh: unsudo: running_as_root:englianhu: tee /tmp/hello-tmpTk0OuoZl.go
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmpTk0OuoZl.go
update-golang.sh: unsudo: running_as_root:englianhu: /usr/local/go/bin/go run /tmp/hello-tmpTk0OuoZl.go
update-golang.sh: hello, world - go1.19
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmpTk0OuoZl.go: SUCCESS
update-golang.sh: running_as_root: yes
update-golang.sh: recursively forcing build cache [/home/englianhu/.cache/go-build] ownership to 1000:1001
update-golang.sh:
update-golang.sh: HINT: If this is the first time you run this script, the env vars
update-golang.sh: updated in the profile will only take effect for new shells.
update-golang.sh: If you want them to affect the current shell, use this:
update-golang.sh:
update-golang.sh: source /etc/profile.d/golang_path.sh
update-golang.sh:
... ... update-golang.sh: HINT: If this is the first time you run this script, the env vars update-golang.sh: updated in the profile will only take effect for new shells. update-golang.sh: If you want them to affect the current shell, use this: update-golang.sh: update-golang.sh: source /etc/profile.d/golang_path.sh update-golang.sh:
Originally posted by @englianhu in https://github.com/scibrokes/setup-centOS7-DO/issues/4#issuecomment-1236249256
$ source /etc/profile.d/golang_path.sh
复制并更新至 https://github.com/englianhu/update-golang 猫城仓库~
## 移除红旗礼逆袭自带go语言版本
sudo rm -rf /usr/lib/go-1.11/
## GO语言官网https://go.dev/dl
wget https://dl.google.com/go/go1.20.linux-amd64.tar.gz
sudo tar -C /usr/lib -xzf go1.20.linux-amd64.tar.gz
sudo rm -rf go1.20.linux-amd64.tar.gz
sudo chmod 777 -R /usr/lib/go
cd /usr/lib/go/
## 方案 01
echo "export PATH=/usr/lib/go/bin:${PATH}" | sudo tee /etc/profile.d/go.sh
source /etc/profile.d/go.sh
go version
## 方案 02
echo "export PATH=/usr/lib/go/bin:${PATH}" | sudo tee -a $HOME/.profile source
source $HOME/.profile
go version
$ go version
go version go1.20 linux/amd64
引用:GO: Download and install
引用:Linux下tar命令解压到指定的目录
https://go.dev/doc/install