How to Install Go on Mac with Brew and Run the Go Tour
Install Go on macOS using Homebrew with brew install go, then install the Go Tour with go install golang.org/x/tour@latest and launch it with the tour command.
This guide walks you through installing the Go programming language on macOS using Homebrew and running the interactive Go Tour locally. The instructions reference the official golang/go repository to explain how the toolchain works under the hood.
Install Go on Mac with Homebrew
Homebrew provides a pre-compiled Go binary through the go formula. This installation places the toolchain under /usr/local/opt/go on Intel Macs or under the Homebrew prefix on Apple Silicon, automatically handling the bin directory in your PATH.
Update Homebrew and Install the Go Formula
First, ensure your local formula index is current, then install Go:
brew update
brew install go
Verify the Installation
Check that the go command is available and displays the correct version:
go version
You should see output similar to go version go1.22.5 darwin/amd64 (or darwin/arm64 on Apple Silicon).
Understanding the Installation Path
The go binary provided by Homebrew is built from the same source tree hosted in the golang/go repository. The main entry point for the go command is implemented in src/cmd/go/main.go, which parses sub-commands like run, build, and install to drive the compiler and linker.
Configure Your Go Environment
While Homebrew installs the compiler and standard library, you should configure your workspace for user-installed binaries.
Set Up GOPATH and PATH
Go defaults to using $HOME/go as the module cache and workspace. Add the following to your shell configuration file (.zshrc or .bash_profile):
export GOPATH="$HOME/go"
export PATH="$PATH:$HOME/go/bin"
These environment variables ensure that binaries installed via go install—such as the Go Tour—are executable from your terminal.
Install and Run the Go Tour
The interactive "Tour of Go" is distributed as a separate module at golang.org/x/tour. You install it using the go install command, which leverages the same toolchain you just set up.
Install the Tour Binary
Fetch and compile the tour program:
go install golang.org/x/tour@latest
This command resolves the module via the Go module proxy, downloads the source, compiles the binary, and places the executable in $GOPATH/bin (or $HOME/go/bin).
Launch the Interactive Tutorial
Start the local web server:
tour
This command starts a server on http://localhost:3999 and opens your default browser. The tour presents interactive Go lessons that execute code snippets in real-time.
How the Tour Uses the Go Toolchain
The tour program relies on the go command infrastructure to compile and run user-submitted code snippets. Specifically, it uses the implementation found in src/cmd/go/internal/run/run.go, which handles the go run command. When you click "Run" in the tour interface, the program writes the snippet to a temporary directory—managed by the logic in src/cmd/go/internal/work—and invokes the compiler chain to produce output.
Summary
- Install Go on macOS using
brew install go, which places the toolchain under/usr/local/opt/goand updates yourPATH. - Verify the installation with
go versionto confirm the binary works correctly. - Configure your environment by setting
GOPATHand adding$HOME/go/binto yourPATHfor user-installed binaries. - Install the tour using
go install golang.org/x/tour@latest, which compiles the binary into your local Go workspace. - Run the tour with the
tourcommand to start the interactive learning environment atlocalhost:3999.
Frequently Asked Questions
Where does Homebrew install Go on macOS?
Homebrew installs Go under /usr/local/opt/go on Intel Macs or under the Homebrew prefix directory on Apple Silicon (typically /opt/homebrew/opt/go). The bin directory containing the go executable is symlinked into /usr/local/bin or /opt/homebrew/bin, making it available in your PATH immediately after installation.
Do I need to set GOPATH when installing Go with Homebrew?
No, setting GOPATH is optional. Modern versions of Go default to using $HOME/go as the workspace if GOPATH is not explicitly set. However, you should add $HOME/go/bin to your PATH environment variable to ensure that binaries installed via go install—such as the tour command—are executable from your terminal.
How do I uninstall the Go Tour?
To remove the Go Tour, delete the tour binary from your GOPATH/bin directory (typically $HOME/go/bin/tour). You can also remove the module cache entry if desired using go clean -modcache, though this affects all cached modules. The tour does not install system-wide files outside of the Go workspace.
Can I run the Go Tour without installing it locally?
Yes, the Go Tour is available online at https://go.dev/tour/. The web version provides the same interactive lessons and code execution environment without requiring local installation. However, running it locally with go install golang.org/x/tour@latest allows offline usage and ensures you are using the version compatible with your installed Go toolchain.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →