To install and manage different versions of Go (Golang) on Ubuntu, you can use several methods. One of the easiest and most flexible ways is using a tool like gvm
(Go Version Manager)
Using gvm
(Go Version Manager)
-
Install Prerequisites
sudo apt-get update sudo apt-get install curl git mercurial make binutils bison gcc
-
Install
gvm
bash < <(curl -sSL https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
-
Source the
gvm
script (or restart your terminal)source ~/.gvm/scripts/gvm
-
Install Go versions with
gvm
To install a specific Go version, for example,1.20
, run:gvm install go1.20
-
Set the Go version to use
You can use the installed version by running:gvm use go1.20 --default
-
Check Go version
go version