How to update Golang version in linux

As software engineers we need to change our development environments base on the software requirements.
In my case to improve my Golang development environment I found out version 1.18.x deliver a new feature call workspaces.

You can follow the next steps to update your golang version or install a different version of golang.

  1. find where go binary is installed
    which go
    and it should return you an output similar to
    /usr/local/go/bin/go
    keep in mind that depending on your Linux Distribution the location of the golang binary may change.
    now we know the location is /usr/local/go
  2. remove the go installation
    rm -f /usr/local/go
  3. download the desired version of golang from go.dev. In my case I want 1.18.1
    wget https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
  4. extract the package
    tar -xvf go1.18.1.linux-amd64.tar.gz
  5. move the new package where the old was
    mv go /usr/local
  6. check if you are using your new golang binary
    go version
    it will return something like
    go version go1.18.1 linux/amd64