Go CLI Cheat Sheet

Core go command workflows for build, run, test, env, fmt, vet, doc, install, list, clean, toolchains, and everyday module-aware development.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Getting Started

Getting Started commands and patterns for the Go command.

Print Go version

Show the selected Go toolchain version.

bashANYgoversion
bash
go version
Notes

Show the selected Go toolchain version. Useful in Go CLI workflows.

Print Go environment

Inspect Go environment variables and effective values.

bashANYgoenv
bash
go env
Notes

Inspect Go environment variables and effective values. Useful in Go CLI workflows.

Print Go environment as JSON

Useful for scripting and debugging setup.

bashANYgoenvjson
bash
go env -json
Notes

Useful for scripting and debugging setup. Useful in Go CLI workflows.

Show help

Show top-level go command help.

bashANYgohelp
bash
go help
Notes

Show top-level go command help. Useful in Go CLI workflows.

Help for build

Show detailed help for go build flags and behavior.

bashANYgohelpbuild
bash
go help build
Notes

Show detailed help for go build flags and behavior. Useful in Go CLI workflows.

Run Build Install

Run Build Install commands and patterns for the Go command.

Run program

Compile and run the current module entrypoint.

bashANYgorun
bash
go run .
Notes

Compile and run the current module entrypoint. Useful in Go CLI workflows.

Run single file

Compile and run a single Go source file.

bashANYgorun
bash
go run main.go
Notes

Compile and run a single Go source file. Useful in Go CLI workflows.

Build current package

Compile the current package or module target.

bashANYgobuild
bash
go build .
Notes

Compile the current package or module target. Useful in Go CLI workflows.

Build named binary

Write the compiled binary to a specific path.

bashANYgobuildbinary
bash
go build -o ./bin/app .
Notes

Write the compiled binary to a specific path. Useful in Go CLI workflows.

Install package

Compile and install a package binary.

bashANYgoinstall
bash
go install ./cmd/myapp
Notes

Compile and install a package binary. Useful in Go CLI workflows.

Install versioned tool

Install a tool at an explicit module version.

bashANYgoinstalltools
bash
go install golang.org/x/tools/cmd/stringer@latest
Notes

Install a tool at an explicit module version. Useful in Go CLI workflows.

Formatting and Quality

Formatting and Quality commands and patterns for the Go command.

Format package sources

Run gofmt across package sources.

bashANYgofmt
bash
go fmt ./...
Notes

Run gofmt across package sources. Useful in Go CLI workflows.

Run vet

Report likely mistakes in Go packages.

bashANYgovet
bash
go vet ./...
Notes

Report likely mistakes in Go packages. Useful in Go CLI workflows.

Run short tests

Run tests while skipping long-running cases.

bashANYgotest
bash
go test -short ./...
Notes

Run tests while skipping long-running cases. Useful in Go CLI workflows.

Run race detector

Detect race conditions in tests or packages.

bashANYgotestrace
bash
go test -race ./...
Notes

Detect race conditions in tests or packages. Useful in Go CLI workflows.

Run coverage

Collect statement coverage while testing.

bashANYgotestcoverage
bash
go test -cover ./...
Notes

Collect statement coverage while testing. Useful in Go CLI workflows.

Documentation and Listing

Documentation and Listing commands and patterns for the Go command.

Show package docs

Print docs for a package.

bashANYgodoc
bash
go doc net/http
Notes

Print docs for a package. Useful in Go CLI workflows.

Show symbol docs

Print docs for a symbol in a package.

bashANYgodoc
bash
go doc net/http Client
Notes

Print docs for a symbol in a package. Useful in Go CLI workflows.

List packages

List packages under the current module.

bashANYgolistpackages
bash
go list ./...
Notes

List packages under the current module. Useful in Go CLI workflows.

List package metadata JSON

Emit package metadata for scripts and tooling.

bashANYgolistjson
bash
go list -json ./...
Notes

Emit package metadata for scripts and tooling. Useful in Go CLI workflows.

Clean build/test caches

Remove build outputs and cached files.

bashANYgocleancache
bash
go clean -cache -testcache -modcache
Notes

Remove build outputs and cached files. Useful in Go CLI workflows.

Toolchains and Env

Toolchains and Env commands and patterns for the Go command.

Persist Go env value

Write a Go env default into the user config.

bashANYgoenvconfig
bash
go env -w GOPRIVATE=github.com/myorg/*
Notes

Write a Go env default into the user config. Useful in Go CLI workflows.

Unset persisted env value

Remove a persisted Go env setting.

bashANYgoenvconfig
bash
go env -u GOPRIVATE
Notes

Remove a persisted Go env setting. Useful in Go CLI workflows.

Force local toolchain

Run with the bundled/local toolchain only.

bashANYgotoolchain
bash
GOTOOLCHAIN=local go test ./...
Notes

Run with the bundled/local toolchain only. Useful in Go CLI workflows.

Allow auto toolchain selection

Let the go command choose a newer toolchain if needed.

bashANYgotoolchain
bash
GOTOOLCHAIN=auto go version
Notes

Let the go command choose a newer toolchain if needed. Useful in Go CLI workflows.

Show V8 options through go tool

Pass through to tool-specific options when needed.

bashANYgotool
bash
go tool compile -help
Notes

Pass through to tool-specific options when needed. Useful in Go CLI workflows.

Recommended next

No recommendations yet.