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
.pkgfile from the Go website and run it. - Homebrew: Use the command
brew install goin 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
PATHenvironment variable after manual installation, sogocommand 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 versionOutput
/usr/local/go/bin/go
go version go1.20.5 darwin/amd64
Quick Reference
Summary of Go installation commands on Mac:
| Action | Command |
|---|---|
| Install Go with Homebrew | brew install go |
| Verify Go version | go version |
| Add Go to PATH (manual install) | export PATH=$PATH:/usr/local/go/bin |
| Reload shell profile | source ~/.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.