go-build
compile Go packages and dependencies
TLDR
Build current package
$ go build
Build specific file$ go build [main.go]
Set output name$ go build -o [binary-name]
Cross-compile$ GOOS=[linux] GOARCH=[amd64] go build
Build with race detector$ go build -race
SYNOPSIS
go build [options] [packages]
DESCRIPTION
go build compiles Go packages and dependencies. It produces an executable binary from the main package or checks compilation for library packages.
The command handles dependency resolution, compilation, and linking. Cross-compilation is built-in via GOOS and GOARCH environment variables, requiring no additional toolchains.
PARAMETERS
PACKAGES
Packages to build.-o FILE
Output file name.-v
Verbose output.-race
Enable race detector.-ldflags FLAGS
Linker flags.-tags TAGS
Build tags.--help
Display help information.
CAVEATS
Main package produces executable. Libraries just check compilation. CGO requires C compiler.
HISTORY
go build is a core command of the Go toolchain, providing fast incremental compilation since Go's release.
SEE ALSO
go(1), go-run(1), go-install(1)
