LinuxCommandLibrary

go-build

compile Go packages and dependencies

TLDR

Build current package

$ go build
copy
Build specific file
$ go build [main.go]
copy
Set output name
$ go build -o [binary-name]
copy
Cross-compile
$ GOOS=[linux] GOARCH=[amd64] go build
copy
Build with race detector
$ go build -race
copy

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community