Setting Up Go
Installing Go gives you one toolchain driven by the go command, and every project lives in a module described by a go.mod file, which can sit in any folder.
Verify the installed toolchain and create a module for a reproducible workspace.
Before tally can count anything, your computer needs the Go toolchain. The good news: Go ships as one download, and a single command, go, compiles, runs, tests and formats everything.
The rule
Install one toolchain, start one module, and let
godrive.
Install. Download the installer for your system from the official site, go.dev, or use a package manager such as Homebrew (brew install go). Then check it in a new terminal:
go versionIf it prints a line such as go version go1.26.0 darwin/arm64, Go is installed and on your PATH. The version number on your machine may differ; anything recent is fine.
Start a module. A module is a folder of Go code with a go.mod file at its root. The file names the module and records which Go version and which outside packages it needs.
mkdir tally
cd tally
go mod init example.com/tallyThat creates:
module example.com/tally
go 1.26The module path looks like a web address because shared modules are usually named after where they live, such as github.com/you/tally. For a private project any sensible name works.
Let go drive. You do not configure a build system. go run, go build and go test read go.mod and work out the rest. If a module asks for a newer Go than you have, the go command can even download that toolchain for you.
A few names you will see:
GOROOTis where Go itself is installed. You rarely touch it.GOPATH(by default~/go) holds downloaded modules and installed tools. Old tutorials say your code must live inside it; with modules, that is no longer true. Put projects anywhere.go envprints all these settings.
For an editor, install the Go extension for VS Code or use GoLand. Both talk to gopls, the Go language server, for completion, jump-to-definition and live errors.