Installing Go
To install Go, do the following:
Remove any existing Go installations
sudo rm -rf /usr/local/goNote: Be sure to backup any existing Go installations before removing them.
Find the latest version of Go from https://golang.org/dl/ then download it
wget https://dl.google.com/go/go1.17.7.linux-amd64.tar.gzNote: Change
go1.17.7.linux-amd64.tar.gzto the most recent version of Go.Extract the archive
tar -xvf go1.17.7.linux-amd64.tar.gzSet permissions on the extracted files
sudo chown -R root:root ./goMove the directory to the
/usr/local/gosudo mv go /usr/localSet the
PATHvariableecho 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profileSet the
GOPATHandGOBINvariablesecho 'export GOPATH=/usr/local/go' >> ~/.profileecho 'export GOBIN=/usr/local/go/bin' >> ~/.profileLog out and log back in to apply the changes
Verify the installation
go versionYou should see something like:
go version go1.17.7 linux/amd64Verify the
GOPATHandGOBINvariables are set correctlygo envYou should see the
GOPATHandGOBINvariables set correctly.
Purging old Go version
If you have issues getting the latest version of Go working, it might be because you have an older version of Go installed with apt-get. To remove the old version of Go, do the following:
sudo apt-get purge golang*
Note: After doing this, you might need to reinstall Go. But first log out and log back in and test with
go version.