Go - Installation & Toolchain
Beginner 10/10
Teacher 10/10
Architect 10/10
Install Go
Download from go.dev/dl and follow the installer for your OS. Then verify in a new terminal:
go version
# Expected: go version go1.xx.x darwin/amd64 (your OS/arch)
Quick OS-specific installs
- macOS (Homebrew):
brew install go which go && go version - Windows:
winget install -e --id GoLang.Go # or: choco install golang # open a new PowerShell, then: go version - Ubuntu/Debian:
sudo snap install go --classic # or from tarball per go.dev/dl instructions go version
Add Go to PATH (if needed)
Most installers handle PATH. If not, add the Go bin and GOPATH bin to PATH:
# bash/zsh
export PATH=$PATH:/usr/local/go/bin:$(go env GOPATH)/bin
GOPATH vs Modules
- Go modules (Go 1.13+): the standard for dependency management. Use
go mod initin your project root. - GOPATH: legacy workspace mode. Prefer modules for new projects.
Environment
GOROOT: where Go is installed (managed by installer).GOPATH: your workspace (default~/go); binaries land in$GOPATH/bin.- Add
$GOPATH/binto PATH to use installed tools.
Core Commands
go run: compile and run a programgo build: build a binarygo test: run testsgo fmt: format codego vet: static checksgo get: add/update dependencies (modules)go mod tidy: clean up module file
Editor setup
- Install VS Code + Go extension, or GoLand, or your preferred editor.
- Enable "Format on save" to auto-run
gofmt.
Quick Start
- Create a folder:
mkdir hello,cd hello - Init module:
go mod init example.com/hello - Create
main.go:
package main
import "fmt"
func main(){ fmt.Println("hello") }
Run with go run . or build with go build.
Exercises
- Install Go and verify
go version. - Initialize a module and run a simple program.