go(1)
Go is a compiled programming language designed for building fast, reliable, and efficient software.
Synopsis
go <command> [arguments]Description
Go (golang) is an open-source compiled language created by Google. It combines the performance of compiled languages with the simplicity of dynamic languages, featuring built-in concurrency, garbage collection, and cross-platform compilation.
The go command is the main toolchain for compiling, testing, installing, and managing Go programs and dependencies. It works with Go modules for dependency management and can build binaries for multiple operating systems and architectures.
Common options
| Flag | What it does |
|---|---|
go build | Compile packages and dependencies into an executable binary |
go run | Compile and run Go program without creating a permanent binary |
go test | Execute tests in Go packages |
go install | Compile and install packages to $GOPATH/bin or $GOBIN |
-v | Verbose output; print names of compiled packages |
-o FILE | Write output to FILE instead of default location |
go mod tidy | Add missing and remove unused module dependencies |
go fmt | Reformat source code to standard Go style |
-race | Enable race condition detector (build/test) |
go get | Download and install packages and dependencies |
Examples
Compile and execute main.go immediately without creating a binary
go run main.goCompile current package and save executable as 'myapp'
go build -o myappRun all tests in current module and all subdirectories
go test ./...Download, compile, and install a package from GitHub
go install github.com/user/package@latestFormat all Go source files in current module to standard style
go fmt ./...Download modules to local cache without building
go mod downloadCompile with verbose output and race detector enabled
go build -v -raceRun benchmarks with memory allocation statistics
go test -bench=. -benchmem