Skip to content

Go Environment Setup on macOS

First PublishedByAtif Alam

This page walks through setting up Go on macOS: check or install the toolchain, fix PATH, bootstrap ~/go, install CLI tools with go install, and verify with a minimal module. For a first CLI after setup, see Go for small ops tools.

Terminal window
go version
which go

If both work, note the version and skip to GOROOT, GOPATH, and modules unless you need a newer release.

Expected output looks like go version go1.22.x darwin/arm64 on Apple Silicon or darwin/amd64 on Intel Macs.

If go is not found, install using one of the options below — pick one path and stick with it.

Avoid mixing Homebrew and the official .pkg installer. Two installs produce confusing which go output and duplicate PATH entries.

Same pattern as other macOS guides in this library:

Terminal window
brew install go
go version

On Apple Silicon, Homebrew usually puts go on PATH via /opt/homebrew/bin. You typically do not need to add /usr/local/go/bin when you use Homebrew only.

Upgrade later with:

Terminal window
brew upgrade go

Download the macOS package from go.dev/dl and run it. This installs Go under /usr/local/go.

Verify:

Terminal window
go version

If go is not found, add the official binary directory to ~/.zshrc:

Terminal window
export PATH=$PATH:/usr/local/go/bin
source ~/.zshrc

Most developers need one Go release. When you need more:

ApproachWhen it fits
Official installs from go.dev/dlPin a specific version per machine; simple and reliable
Homebrew versioned formulaeTeam already uses Homebrew for everything
asdf with the Go pluginSame “one tool, many runtimes” idea as pyenv for Python
gvmLegacy option; can be fragile on newer macOS — use only if your team already standardizes on it

Example gvm flow (optional):

Terminal window
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
gvm install go1.22.0
gvm use go1.22.0 --default

Replace go1.22.0 with a current version from go.dev/dl.

Go uses a few directory concepts:

  • GOROOT — where the Go toolchain itself is installed (Homebrew or /usr/local/go).
  • GOPATH — your Go workspace; default ~/go. Holds go install binaries (~/go/bin) and the module download cache (~/go/pkg/mod).
  • Modules — modern projects use go.mod in any folder. You do not need to put source code under $GOPATH/src.
Terminal window
go env GOROOT
go env GOPATH
go env GOMODCACHE
go env

Installed CLI tools from go install land in $GOPATH/bin (usually ~/go/bin).

The ~/go directory does not exist on a fresh install. That is normal — Go creates it when you first go install a tool or run go mod init in a project.

Install a standard tool that formats imports and bootstraps your workspace:

Terminal window
go install golang.org/x/tools/cmd/goimports@latest

This will:

  • Create ~/go/ and ~/go/bin/ if they are missing
  • Install the goimports binary under ~/go/bin

Verify the binary exists (full path works even before the next step):

Terminal window
ls ~/go/bin
# Expected: goimports

go install does not require $GOPATH/bin on PATH, but which goimports only succeeds after you add that directory to PATH below.

Add these lines to ~/.zshrc so installed tools are callable from anywhere:

Terminal window
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

If you used the official .pkg installer, also ensure the Go toolchain is on PATH:

Terminal window
export PATH=$PATH:/usr/local/go/bin

If you used Homebrew only, the GOPATH and $GOPATH/bin lines above are usually enough — skip /usr/local/go/bin unless which go points there.

Apply changes:

/Users/yourusername/go/bin/goimports
source ~/.zshrc
which goimports

Homebrew install:

Terminal window
# Go setup (Homebrew)
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Official .pkg install:

Terminal window
# Go setup (official installer)
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH/bin

Confirm the toolchain end-to-end:

Terminal window
mkdir -p ~/hello-go && cd ~/hello-go
go mod init example.com/hello

Create main.go:

package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}

Run it:

Terminal window
go run .

Expected: Hello, Go!

For a slightly larger CLI with flags, continue to Go for small ops tools. Cloning private modules may require OpenSSH client keys and GOPRIVATE — see that ops page for a one-line sketch.

TaskCommand
Check Go versiongo version
Find GOROOT / GOPATHgo env GOROOT / go env GOPATH
See all Go env varsgo env
Install a Go toolgo install <package>@latest
Upgrade (Homebrew)brew upgrade go
Reload shell configsource ~/.zshrc
  • Run go version and which go before installing — avoid duplicate toolchains.
  • Homebrew vs official .pkg need different PATH lines; do not blindly copy both.
  • GOPATH (~/go) holds go install tools and the module cache; projects live anywhere with go mod init.
  • Bootstrap with go install …/goimports@latest, then put $GOPATH/bin on PATH.
  • Verify with a tiny module and go run . before moving on to CLIs or services.