Install Go
Install Go
Section titled “Install Go”go-zero requires Go 1.21 or later. This page shows how to install Go on macOS, Linux, and Windows, and how to verify the setup.
Check Existing Installation
Section titled “Check Existing Installation”go version# go version go1.23.4 linux/amd64If the version is ≥ 1.21, skip to Validate Environment. Otherwise install or upgrade below.
Install
Section titled “Install”# Using Homebrew (recommended)brew install go
# Or download the .pkg installer from:# https://go.dev/dl/# Download and extract (replace 1.23.4 with the latest)wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gzsudo rm -rf /usr/local/gosudo tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gzAdd Go to your shell profile (~/.bashrc, ~/.zshrc, etc.):
export PATH=$PATH:/usr/local/go/binexport GOPATH=$HOME/goexport GOBIN=$GOPATH/binexport PATH=$PATH:$GOBINReload:
source ~/.zshrc # or ~/.bashrcWindows
Section titled “Windows”Download and run the .msi installer from go.dev/dl. The installer updates PATH automatically.
Validate Environment
Section titled “Validate Environment”go version# go version go1.23.4 ...
go env GOPATH GOBIN GOMODCACHE# /home/user/go# /home/user/go/bin# /home/user/go/pkg/modMake sure GOBIN is in your PATH — this is where goctl and other Go-installed binaries live.
Troubleshooting
Section titled “Troubleshooting”| Problem | Fix |
|---|---|
go: command not found | Add /usr/local/go/bin to PATH and reload shell |
goctl: command not found after install | Add $GOBIN to PATH |
| Module download errors | Run go env -w GOPROXY=https://goproxy.cn,direct (China) |