How to Update Go on macOS: Step-by-Step Guide

Written by

in

Keeping Go Sharp on macOS: A Complete Guide to Updating Your Go Toolchain

Whether you are chasing performance improvements in the latest release (such as Go 1.27.4), patching security vulnerabilities, or adopting new standard library features, keeping Go up to date on macOS is a quick process—provided you don’t accidentally tangle multiple installations together.

Because macOS developers install Go in a few different ways, the cleanest upgrade path depends on how Go originally landed on your machine.


Step 0: Check Your Current Setup

Before installing anything new, open your terminal and inspect what you currently have running:

go version
which go

The which go output tells you which installation method you used:

  • /usr/local/go/bin/go: Installed via the official .pkg installer or manual tarball.
  • /opt/homebrew/bin/go (Apple Silicon) or /usr/local/bin/go (Intel): Installed via Homebrew.
  • ~/.gvm/... or ~/.asdf/... or ~/sdk/...: Managed by a version manager or Go’s native toolchain switcher.

Golden Rule: Stick to one installation method. Mixing Homebrew Go with the official .pkg installer often leads to PATH conflicts where go version shows one release while your IDE compiles with another.


Method 1: Updating via Homebrew (Fastest for CLI Users)

If you originally installed Go with Homebrew, upgrading takes two commands:

brew update
brew upgrade go

Homebrew automatically downloads the latest stable formula (currently tracking the Go 1.27 series), unlinks the older version, and updates your symlinks.

Cleaning Up Old Versions

Homebrew keeps older versions cached on disk in case you need to roll back. Once you confirm your projects build cleanly on the new version, free up disk space by running:

brew cleanup go

Method 2: The Official macOS .pkg Installer

If you prefer managing Go directly from go.dev/dl without third-party package managers, the official .pkg installer handles upgrades cleanly:

  1. Download the right architecture:
    • Apple Silicon (M1/M2/M3/M4+): Grab the darwin-arm64.pkg file.
    • Intel Macs: Grab the darwin-amd64.pkg file.
  2. Run the installer: Double-click the downloaded .pkg file and follow the prompts. The installer automatically removes the previous /usr/local/go directory and writes the new version in its place.
  3. Restart your terminal (or run hash -r in zsh/bash) so your shell refreshes its command cache.

Method 3: Manual Tarball Upgrade (Custom Paths)

If you maintain Go manually using .tar.gz archives—for instance, in CI environments or custom directories—never extract a new archive directly over an existing /usr/local/go folder, as leftover files from older releases can corrupt the toolchain.

Always remove the old tree first, then extract in a single step:

sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.27.4.darwin-arm64.tar.gz

(Replace the filename with your target version and architecture.)


Method 4: Automatic Toolchain Switching via go.mod

Modern Go includes built-in toolchain management (GOTOOLCHAIN). Even if your system-wide Go installation is a minor version behind, Go can automatically download and run the exact toolchain specified in a project’s go.mod file.

To upgrade a specific project to a newer Go version:

  1. Open your project directory and update the go directive in go.mod:
    go mod edit -go=1.27.4
    
  2. Run any standard command such as go test ./... or go build. If your local system binary is older than 1.27.4, Go automatically fetches the requested toolchain into your module cache and executes it seamlessly.

Post-Update Checklist

Once go version confirms your upgrade succeeded, take two minutes to refresh your surrounding environment:

  • Recompile global CLI tools: Tools installed via go install (like gopls, golangci-lint, or dlv) were compiled against your old Go runtime. Reinstall them to benefit from compiler optimizations and bug fixes:
    go install golang.org/x/tools/gopls@latest
    
  • Update project dependencies (optional): Inside your repository, run go get -u ./... followed by go mod tidy if you want to pull in updated third-party packages alongside your toolchain bump.
  • Reload your editor: If you use VS Code or GoLand, restart the language server (Go: Restart Language Server in VS Code) so code completion and diagnostics recognize new standard library APIs.

Quick Troubleshooting

| Symptom | Likely Cause | Fix |
| :— | :— | :— |
| go version still shows the old version | Shell path cache or duplicate binary in PATH | Run which -a go to find duplicate binaries and adjust ~/.zshrc |
| permission denied during go install | GOPATH or GOBIN pointing to a root-owned folder | Verify go env GOPATH points to ~/go and ensure export PATH="$PATH:$(go env GOPATH)/bin" is in ~/.zshrc |
| IDE complains about unknown stdlib functions | Language server (gopls) is outdated | Run go install golang.org/x/tools/gopls@latest and restart your IDE |

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *