Logo Tuxnuxt
Published on

How to Upgrade Go (Golang) on Ubuntu 22.04/24.04 Step-by-Step

Authors

How to Upgrade Go (Golang) on Ubuntu 22.04/24.04 — Step-by-Step

Upgrade Go the official way using the instructions from go.dev/install. This guide shows you how to remove the old toolchain, install the latest to /usr/local, update your PATH, and verify the upgrade. Alternative methods (APT, Snap, asdf/gvm) are also included.

Install Multiple PHP di XAMPP Linux



Prerequisites

  • Ubuntu 22.04 or 24.04 (works on other recent versions too)
  • sudo access
  • A shell (bash/zsh) and basic CLI tools (curl, tar, sha256sum)

1) Check your current Go version

go version || echo "Go is not in PATH"

If it prints a version (e.g., go version go1.20.5 linux/amd64), you’re set to upgrade. Otherwise, follow the install steps below.


This is the clean, vendor-supported method.

2.1 Remove the old toolchain (keeps your projects untouched)

sudo rm -rf /usr/local/go

This removes the toolchain only, not your project files ($GOPATH, modules, etc.).

2.2 Download the latest Go

  1. Open go.dev/dl and copy the latest Linux tarball link for your CPU (usually linux-amd64 or linux-arm64).
  2. Use variables so it’s easy to repeat (optional):
# 👇 Replace these with the latest you copied from go.dev/dl
VERSION="go1.xx.x"
ARCH="linux-amd64"   # or linux-arm64 on ARM
URL="https://go.dev/dl/${VERSION}.${ARCH}.tar.gz"

curl -LO "$URL"

2.3 (Optional) Verify the checksum

On the downloads page, copy the SHA256 value for your tarball, then:

# Paste the expected SHA256 from the website into EXPECTED
EXPECTED="paste_the_sha256_here"
echo "${EXPECTED}  ${VERSION}.${ARCH}.tar.gz" | sha256sum -c -

If you see OK, the file is intact. Otherwise, re-download.

2.4 Extract to /usr/local

sudo tar -C /usr/local -xzf "${VERSION}.${ARCH}.tar.gz"

This creates /usr/local/go.

2.5 Add Go to your PATH

Append to your shell profile:

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
# If you use zsh:
# echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.zshrc

Reload your shell:

source ~/.bashrc  # or: exec $SHELL

2.6 Verify

go version
go env GOROOT GOPATH | tr ' ' '\n'

You should see the new version and GOROOT=/usr/local/go.
That’s it — Go is upgraded.


3) Keep the old version (optional, side-by-side)

If you want a rollback path:

# Before step 2.1:
sudo mv /usr/local/go "/usr/local/go-$(go version | awk '{print $3}')"
# Then continue with the new install to /usr/local/go

Switch by adjusting PATH to point to the desired .../go/bin.


4) Alternative Methods

  • Install asdf: asdf-vm.com
  • Add the Go plugin and install:
asdf plugin add golang https://github.com/asdf-community/asdf-golang.git
asdf install golang latest
asdf global golang latest
go version

4.2 gvm (Go Version Manager)

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
source ~/.gvm/scripts/gvm
gvm install go1.xx.x
gvm use go1.xx.x --default
go version

4.3 Snap (quick, may lag behind latest)

sudo snap install go --classic
go version

4.4 APT (often older on LTS)

Ubuntu’s APT repo usually trails the latest Go. Use only if you accept a slightly older version:

sudo apt update
sudo apt install golang
go version

5) Common Pitfalls & Fixes

  • go: go.mod requires go 1.y
    Your module requires a newer Go than installed. Upgrade using the tarball/asdf method.
  • go: command not found
    Ensure /usr/local/go/bin is in PATH and you reloaded your shell (source ~/.bashrc).
  • Mixed installs (APT + tarball)
    Remove APT’s Go (sudo apt remove golang-go) or ensure the tarball path comes first in PATH.
  • ARM machines
    Use linux-arm64 tarball.

6) Quick Uninstall

sudo rm -rf /usr/local/go
# Remove PATH line from ~/.bashrc (or ~/.zshrc), then:
source ~/.bashrc

FAQ

Q: Will this affect my projects?
A: No. Your projects and modules live outside /usr/local/go. Only the compiler/toolchain is replaced.

Q: Where should my workspace be?
A: With Go modules, you can work anywhere. GOPATH defaults to ~/go (see go env GOPATH).

Q: Is the official tarball safe?
A: Yes — verify the SHA256 from go.dev/dl for integrity.


Happy coding!

Semoga bermanfaat.

Terimakasih
(Tuxnuxt.com)