Skip to content

Instantly share code, notes, and snippets.

@nikhita
Last active April 7, 2025 21:32
Show Gist options
  • Save nikhita/432436d570b89cab172dcf2894465753 to your computer and use it in GitHub Desktop.
Save nikhita/432436d570b89cab172dcf2894465753 to your computer and use it in GitHub Desktop.
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

$ sudo rm -rf /usr/local/go

2. Install the new version

Go to the downloads page and download the binary release suitable for your system.

3. Extract the archive file

To extract the archive file:

$ sudo tar -C /usr/local -xzf /home/nikhita/Downloads/go1.8.1.linux-amd64.tar.gz

4. Make sure that your PATH contains /usr/local/go/bin

$ echo $PATH | grep "/usr/local/go/bin"
@marcelloinfoweb
Copy link

marcelloinfoweb commented Sep 22, 2024

Modified for ARM64 versions

#!/usr/bin/env bash

version=$(go version 2>/dev/null || echo "none")
release=$(wget -qO- "https://golang.org/VERSION?m=text" | awk '/^go/{print $0}')

if [[ $version == *"$release"* ]]; then
    echo "The local Go version ${release} is up-to-date."
    exit 0
else
    echo "The local Go version is ${version}. A new release ${release} is available."
fi

release_file="${release}.linux-arm64.tar.gz"

tmp=$(mktemp -d)
cd $tmp || exit 1

echo "Downloading https://go.dev/dl/$release_file ..."
curl -OL https://go.dev/dl/$release_file

sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf $release_file

rm -rf $tmp

cd ~

export PATH=$PATH:/usr/local/go/bin:$PATH

version=$(go version)
if [[ $version == *"$release"* ]]; then
    echo "Now, local Go version is $version"
else
    echo "Failed to update Go. Current version is still $version."
    exit 1
fi

@wathika-eng
Copy link

@draco1725
Copy link

@wathika-eng

Thanks bro, well scripted and it helped me great work

@dxps
Copy link

dxps commented Mar 6, 2025

@wathika-eng Thanks for the ref! 🙏 Indeed, it works like a charm!

Previously, I had Go 1.24 manually installed (extracted, to be precise) in $HOME/apps/go.

The script (wget https://git.io/go-installer.sh && bash go-installer.sh) discovered that
and just ask my confirmation to update it. And that's it! 🥰

@lib4u
Copy link

lib4u commented Mar 18, 2025

https://github.com/lib4u/goinstall
i just make shell script for linux
this can update go to latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment