Go Toolchain Basics
10 examples to get you started with Go Toolchain - 7 basic and 3 intermediate.
Search across all documentation pages
10 examples to get you started with Go Toolchain - 7 basic and 3 intermediate.
mkdir tooldemo && cd tooldemo && go mod init example.com/tooldemo.Confirm which Go release is active before debugging build differences.
go versiongo env GOVERSION prints only the version string for scripts.Related: The go Command: Build, Test, and Module Lifecycle - how the driver fits together
Compile the current package without installing globally.
go build -o bin/server ./cmd/servergo build with no -o names the binary after the directory (server for cmd/server).$?.-trimpath in release pipelines to strip file paths from binaries.Related: go build, run, install & clean - flags and cache behavior
Compile to a temp binary and execute in one step.
go run .--: go run . --port 8080.go run ./cmd/worker targets a specific package main.Related: go build, run, install & clean - when to prefer
buildoverrun
Run tests in the current directory.
go test -v .-v prints each test name as it runs.*_test.go files beside production code.Related: go test, list & generate - patterns, race, and benches
Exercise the whole module tree.
go test ./..../... expands to every package under the module root.-count=1 to disable test result caching when debugging flakes.-race in CI for data-race detection.Related: go test, list & generate -
-race,-cover, and benchmarks
go mod init creates the module root file.
go mod init example.com/tooldemo
cat go.modgo 1.26 in go.mod declares the minimum language version.go.mod per module root; subpackages share it.Related: go mod tidy, vendor, download & graph - keeping requires accurate
Sync go.mod with actual imports.
go mod tidyrequire lines and removes unused modules.go.sum checksum lines for every retained module.Related: go mod tidy, vendor, download & graph - vendor and graph commands
Catch suspicious constructs the compiler allows.
go vet ./...fmt verbs.go test, so it compiles packages first.Related: go fix Modernizers & go vet Analyzers - fix rewrites and custom analyzers
Inspect what the loader sees before a build.
go list ./...
go list -m -versions golang.org/x/syncgo list prints import paths, test status, and build tags applied.-m switches to module mode for version queries.go list -m all to dump the full build list for audits.Related: go test, list & generate - JSON output and
-ftemplates
Control which Go release executes commands.
go env GOTOOLCHAIN
GOTOOLCHAIN=go1.26.0 go versionauto may download a newer patch that satisfies go.mod.GOTOOLCHAIN=local forbids automatic toolchain downloads.go directive in go.mod so teammates resolve the same baseline.Related: Cross-Compilation & Private Module Proxies - env vars for builds and modules
Stack versions: This page was written for Go 1.26.x (Green Tea GC default, go fix modernizers - verify patch at build), chi (latest - verify at build), gin (latest - verify at build), echo (latest - verify at build), google.golang.org/grpc (latest - verify at build), sigs.k8s.io/controller-runtime (latest - verify at build), kubebuilder (latest - verify at build), tinygo (latest - verify board targets at build), wazero (latest - verify at build), and golangci-lint (latest - verify linter set at build).
Reviewed by Chris St. John·Last updated Jul 18, 2026