Update golang version Linux or macOS

Update golang version Linux or macOS

This article will show you how to update Go to the newest version for Linux or macOS.

To update it you need to remove your existing go folder, then reinstall the newest version. The package link provided here is the latest version at the time of this article creation. Please notify me if there is a newer version published so I can update the link.

Remove existing go

First, you need to remove your existing golang.

sudo rm -rf /usr/local/go

If you don’t know where your golang is you can use which. It will show you where your go is located.

which go  
#in my case, it shows /usr/local/go/bin/go

You should remove the folder containing /bin/go. In my case, I removed /usr/local/go.

Download latest go version

Use curl to download the package. If you like to install another version, you can go to https://golang.org/dl/ .

We will download golang instalation package then extract it. It will be extracted to directory go. So if you already had directory named go in your currect directory, you should download it to another directory.
For Linux:

curl -O https://dl.google.com/go/go1.21.0.linux-amd64.tar.gz

For Mac:

curl -O https://dl.google.com/go/go1.21.0.darwin-amd64.tar.gz

Extract the package

This will extract the package into folder go and move it to /usr/local

tar -xvf go1.21.0.linux-amd64.tar.gz
sudo mv go /usr/local

You need to update GOROOT if the installation folder is different from the previously installed go.

export GOROOT=/usr/local/go

Verify the installation

Use this command to verify that the installation is successful.

go version

It should show the newest golang version.

If you got something like go: command not found. You need to add $GOROOT/bin to your PATH variable.

export PATH=$PATH:$GOROOT/bin

Great! Your golang is successfully updated.

Edit: Update go version to go1.21.0

go  linux  macOS 

See also

comments powered by Disqus