go build
The go subcommand that compiles a package and its dependencies into an executable file and prints nothing when it succeeds.
In more detail
With -o you choose the output file name, so go build -o probe . leaves a binary called probe in the current directory. Silence means success; any output is an error to read. The same compiler is used by go run and go install, and only where the result goes differs.
Examples
go build -o probe .CGO_ENABLED=0 GOOS=linux go build -o healthcheck .Related terms
- go run — The go subcommand that compiles a program to a temporary place and runs it straight away, leaving no binary behind.
- go install — The go subcommand that compiles a program and places the binary in the bin folder under your Go path, so it works as a command anywhere.
- binary — A compiled program file that a computer runs directly, as opposed to the source code it was built from.
- compiler — A program that translates source code a person wrote into a form a machine or runtime can execute, checking it for errors on the way.
- cross compilation — Building a program on one kind of machine for a different operating system or processor, such as a Linux binary on a Mac.
Taught in
- What Go Is and Why It Matters — Concurrent Systems Programming with Go
- Go Workspaces and Modules — Concurrent Systems Programming with Go
- Your First Program and go run — Concurrent Systems Programming with Go
- Building Static Binaries — Concurrent Systems Programming with Go
- Shipping in Scratch and Distroless Images — Concurrent Systems Programming with Go
- Containerizing and Testing the Final Build — Concurrent Systems Programming with Go