Script to update go version

Although Go installation it’s a pretty straight-forward process, it can be done even easier if a script is used to install and update your golang installation.

We are going to use update-golang script.

$ go version

go version go1.17.6 linux/arm64

$ git clone https://github.com/udhos/update-golang.git

Clonando en 'update-golang'...
remote: Enumerating objects: 706, done.
remote: Counting objects: 100% (62/62), done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 706 (delta 28), reused 39 (delta 17), pack-reused 644
Recibiendo objetos: 100% (706/706), 104.27 KiB | 1.30 MiB/s, listo.
Resolviendo deltas: 100% (363/363), listo.

$ sudo ./update-golang.sh

update-golang.sh: version 0.25
update-golang.sh: find_latest: found last release: 1.18.2
update-golang.sh: user: uid=0(root) gid=0(root) grupos=0(root),4(adm),20(dialout),119(wireshark),145(kaboxer)
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.18.2
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=arm64
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: 
update-golang.sh: will install golang go1.18.2.linux-arm64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.18.2.linux-arm64.tar.gz is remote
--2022-05-14 18:17:46--  https://storage.googleapis.com/golang/go1.18.2.linux-arm64.tar.gz
Resolviendo storage.googleapis.com (storage.googleapis.com)... 142.250.184.16, 142.250.184.176, 142.250.185.16, ...
Conectando con storage.googleapis.com (storage.googleapis.com)[142.250.184.16]:443... conectado.
Petición HTTP enviada, esperando respuesta... 200 OK
Longitud: 108861264 (104M) [application/x-gzip]
Grabando a: «/usr/local/go1.18.2.linux-arm64.tar.gz»

/usr/local/go1.18.2.linux-arm64.tar.gz                      100%[========================================================================================================================================>] 103,82M  20,0MB/s    en 5,8s    

2022-05-14 18:17:52 (18,0 MB/s) - «/usr/local/go1.18.2.linux-arm64.tar.gz» guardado [108861264/108861264]

update-golang.sh: remove_old_link: not found symlink for old install
update-golang.sh: previous install renamed to: /usr/local/go-20220514-181752
update-golang.sh: untar: tar -x -f /usr/local/go1.18.2.linux-arm64.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.18.2.linux-arm64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: unsudo: running_as_root:ruben: /usr/local/go/bin/go version
update-golang.sh: go version go1.18.2 linux/arm64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: unsudo: running_as_root:ruben: mktemp -t hello-tmpXXXXXXXX
update-golang.sh: unsudo: running_as_root:ruben: tee /tmp/hello-tmp9WG8G3Es.go
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmp9WG8G3Es.go
update-golang.sh: unsudo: running_as_root:ruben: /usr/local/go/bin/go run /tmp/hello-tmp9WG8G3Es.go
update-golang.sh: hello, world - go1.18.2
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmp9WG8G3Es.go: SUCCESS
update-golang.sh: running_as_root: yes
update-golang.sh: recursively forcing build cache [/home/ruben/.cache/go-build] ownership to 1000:1000
update-golang.sh: remember to delete previous install saved as: /usr/local/go-20220514-181752
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: 

$ go version

go version go1.18.2 linux/arm64

To finish the setup, the shell PATH should be updated.

  • The path ‘/usr/local/go/bin’ is added to PATH using ‘/etc/profile.d/golang_path.sh’.
  • Only if needed, GOROOT is properly setup, also using ‘/etc/profile.d/golang_path.sh’.
  • Alternatively, can be edited manually to .bashrc or .zshrc:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Deja una respuesta

Tu dirección de correo electrónico no será publicada.