Download the official .pkg installer from the Go website or use Homebrew to install the latest version, then verify the setup by running go version in your terminal. The Homebrew method is generally preferred for its ease of updates and integration with other development tools.
If you prefer the official installer, download the macOS package (.pkg) from https://go.dev/dl/, run it, and follow the prompts. This installs Go to /usr/local/go and adds the binary to your PATH automatically. For a more automated approach, use Homebrew if you have it installed:
brew install go
Once installed, verify the installation and check the version:
go version
If the command returns a version number (e.g., go version go1.22.4 darwin/amd64), you are ready to code. If you receive a "command not found" error, ensure your shell is configured to read the PATH. For the official installer, this usually happens automatically, but if you installed via Homebrew and still face issues, you might need to reload your shell configuration:
source ~/.zshrc # or source ~/.bash_profile depending on your shell
To manage Go modules and dependencies effectively, ensure your GOPATH is set correctly, though modern Go (1.11+) handles module paths automatically. You can create a simple test project to confirm everything works:
mkdir -p ~/go/src/hello
cd ~/go/src/hello
cat > main.go <<EOF
package main
import "fmt"
func main() {
fmt.Println("Go is installed on macOS!")
}
EOF
go run main.go
This should output "Go is installed on macOS!" without errors. If you plan to use Go with IDEs like VS Code or GoLand, no additional configuration is typically needed as long as the go binary is in your PATH. For system-wide updates in the future, simply run brew upgrade go if using Homebrew, or download the new .pkg file from the official site for the manual method.