0
0
GoHow-ToBeginner · 3 min read

How to Install Go on Mac: Step-by-Step Guide

To install Go on a Mac, download the official installer from the golang.org website or use Homebrew by running brew install go in the Terminal. After installation, verify it by running go version.
📐

Syntax

There are two main ways to install Go on a Mac:

  • Official installer: Download a .pkg file from the Go website and run it.
  • Homebrew: Use the command brew install go in the Terminal.

After installation, use go version to check the installed Go version.

bash
brew install go

go version
Output
go version go1.20.5 darwin/amd64
💻

Example

This example shows how to install Go using Homebrew and verify the installation.

bash
brew install go

go version
Output
Updating Homebrew... ==> Downloading https://formulae.brew.sh/api/formula.json ==> Installing dependencies for go: ... ==> Installing go ==> Pouring go-1.20.5.monterey.bottle.tar.gz ==> Caveats Go is installed. ==> Summary 🍺 /usr/local/Cellar/go/1.20.5: 15,000 files, 370MB go version go1.20.5 darwin/amd64
⚠️

Common Pitfalls

Common mistakes when installing Go on Mac include:

  • Not updating PATH environment variable after manual installation, so go command is not found.
  • Using an outdated installer or Homebrew formula.
  • Conflicts if multiple Go versions are installed.

To fix PATH, add export PATH=$PATH:/usr/local/go/bin to your shell profile (~/.zshrc or ~/.bash_profile).

bash
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.zshrc
source ~/.zshrc

# Verify
which go

go version
Output
/usr/local/go/bin/go go version go1.20.5 darwin/amd64
📊

Quick Reference

Summary of Go installation commands on Mac:

ActionCommand
Install Go with Homebrewbrew install go
Verify Go versiongo version
Add Go to PATH (manual install)export PATH=$PATH:/usr/local/go/bin
Reload shell profilesource ~/.zshrc or source ~/.bash_profile

Key Takeaways

Use Homebrew with 'brew install go' for the easiest Go installation on Mac.
Always verify installation by running 'go version' in Terminal.
If Go command is not found, add '/usr/local/go/bin' to your PATH environment variable.
Keep Go updated by regularly running 'brew update' and 'brew upgrade go'.
Avoid multiple Go versions to prevent conflicts.