Skip to main content

Installing Go

To install Go, do the following:

  1. Remove any existing Go installations

     sudo rm -rf /usr/local/go

    Note: Be sure to backup any existing Go installations before removing them.

  2. 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.

  3. Extract the archive

     tar -xvf go1.17.7.linux-amd64.tar.gz
  4. Set permissions on the extracted files

     sudo chown -R root:root ./go
  5. Move the directory to the /usr/local/go

     sudo mv go /usr/local
  6. Set the PATH variable

     echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
  7. Set the GOPATH and GOBIN variables

     echo 'export GOPATH=/usr/local/go' >> ~/.profile
     echo 'export GOBIN=/usr/local/go/bin' >> ~/.profile
  8. Log out and log back in to apply the changes

  9. Verify the installation

     go version

    You should see something like:

    go version go1.17.7 linux/amd64
  10. Verify the GOPATH and GOBIN variables are set correctly

     go env

    You should see the GOPATH and GOBIN 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.