Installing Go
To install Go, do the following:
Remove any existing Go installations
sudo rm -rf /usr/local/go
Note: 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.gz
Note: Change
go1.17.7.linux-amd64.tar.gz
to the most recent version of Go.Extract the archive
tar -xvf go1.17.7.linux-amd64.tar.gz
Set permissions on the extracted files
sudo chown -R root:root ./go
Move the directory to the
/usr/local/go
sudo mv go /usr/local
Set the
PATH
variableecho 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
Set the
GOPATH
andGOBIN
variablesecho 'export GOPATH=/usr/local/go' >> ~/.profile
echo 'export GOBIN=/usr/local/go/bin' >> ~/.profile
Log out and log back in to apply the changes
Verify the installation
go version
You should see something like:
go version go1.17.7 linux/amd64
Verify the
GOPATH
andGOBIN
variables are set correctlygo env
You should see the
GOPATH
andGOBIN
variables 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
.