Skip to content

Instantly share code, notes, and snippets.

@nikhita
Last active July 19, 2025 12:07
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"
@theaog
Copy link

theaog commented Jun 8, 2023

@dxps
Copy link

dxps commented Jun 8, 2023

@theaog My preference is to keep different apps installed in $HOMEDIR/apps.
Yes, GOROOT can be considered and this would be more flexibile.

But I think it's misleading to extract the release archive into $GOROOT/go
(as you put it in the script above: sudo tar -C "${goroot//go}").
Currently, GOROOT on my side - with the current version - is /home/dxps/apps/go1.20.4.

But if your recently posted script works, that's the whole point! 👏

@DieTime
Copy link

DieTime commented Jun 21, 2023

Just use go-up project that supports both Linux and MacOS and
automatically determines where to install the new go version based
on the previous one.

Single line solution using curl

curl -sL https://raw.githubusercontent.com/DieTime/go-up/master/go-up.sh | bash

Single line solution using wget

wget -qO- https://raw.githubusercontent.com/DieTime/go-up/master/go-up.sh | bash

@laurentknauss
Copy link

I switched to go1.21 version following your prompts , works great!

@dxps
Copy link

dxps commented Sep 1, 2023

Unfortunately, that go-up.sh solution doesn't cover some cases.

See a concrete example of how things can be destroyed:

…/apps ❯ curl -sL https://raw.githubusercontent.com/DieTime/go-up/master/go-up.sh | bash
❌ Go not installed, nothing to update
…/apps ❯ 
…/apps ❯ GOBIN=$(which go 2> /dev/null) && echo $GOBIN
…/apps ❯ 
…/apps ❯ tar zxf /disk2t/files/kits/dev/go/go1.21.0.linux-amd64.tar.gz 
…/apps took 1s❯ 
…/apps ❯ 
…/apps ❯ GOBIN=$(which go 2> /dev/null) && echo $GOBIN
/home/dxps/apps/go/bin/go
…/apps ❯ 
…/apps ❯ curl -sL https://raw.githubusercontent.com/DieTime/go-up/master/go-up.sh | bash
❌ Couldn't download and unpack go with version 1.21.0
time 2023-08-04T20:14:06Z
…/apps took 1s❯ 
…/apps ❯ ls -l go/
total 0
…/apps ❯

@Olanetsoft
Copy link

Thank you

@SahilDhingraa
Copy link

windows update?

@dxps
Copy link

dxps commented Nov 2, 2023

@SahilDhingraa Plenty of options to consider. As an example, check this out.

@Tuanm
Copy link

Tuanm commented Nov 25, 2023

I have sketched a simple script to automate the task:

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

Thanks, bro!

@cryptopunkstar
Copy link

Thank you I practice V2 Sei Network on Ubuntu !!

@renanbastos93
Copy link

I have sketched a simple script to automate the task:

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

Thanks @udhos !!

🔝 thanks a lot

@herloncosta
Copy link

I have sketched a simple script to automate the task:

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

Great work man!

Very good solution, thanks!!

@HassanAarzoo
Copy link

You can also try brew upgrade go if you have installed go via brew

@renanbastos93
Copy link

Of course @HassanAarzoo but the problem to updated using raspibian.

@pask01
Copy link

pask01 commented May 21, 2024

Worked fine, thanks! I also had to remove old versions of Go from /usr/lib and /usr/share

$ rm -rf /usr/lib/go
$ rm -rf /usr/lib/go-1.13

$ rm -rf /usr/share/go
$ rm -rf /usr/share/go-1.13

@okedialf
Copy link

I have sketched a simple script to automate the task:

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

Great work man!

Awesome

@okedialf
Copy link

Thank you @Tuanm

@Tuanm
Copy link

Tuanm commented May 27, 2024

Thank you @Tuanm

What did you thank me for, bro? :'v

@CollinsWanjau
Copy link

After installing the latest go-system-wide, i get this version colloso@colloso-ThinkCentre-M73:~/Documents/Go/hello$ go version go version go1.20.3 linux/amd64

@catgoose
Copy link

catgoose commented Jul 6, 2024

Thank you @Tuanm

What did you thank me for, bro? :'v

Thanks chief

@michalis-papamichael
Copy link

Thanks

@pa035
Copy link

pa035 commented Sep 10, 2024

I have sketched a simple script to automate the task:

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

Worked for me. Any script that automatically cleans and removes the temporary files used for the installation?

@GuilhermeBn198
Copy link

guys, i've combined your implementations and gave it a little plus:

#!/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-amd64.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 GOROOT=/usr/local/go
export PATH=$GOROOT/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

@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

@ggcr
Copy link

ggcr commented Jul 19, 2025

Now you can use go's own toolchain

go get [email protected]

@dxps
Copy link

dxps commented Jul 19, 2025

@ggcr Unfortunately, it doesn't work globally (outside of a project/module):

~ ❯ go get [email protected]
go: go.mod file not found in current directory or any parent directory.
	'go get' is no longer supported outside a module.
	To build and install a command, use 'go install' with a version,
	like 'go install example.com/cmd@latest'
	For more information, see https://golang.org/doc/go-get-install-deprecation
	or run 'go help get' or 'go help install'.
~

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