Last Updated: May 22, 2026
Go's toolchain can build a binary for one operating system and CPU architecture while running on another. You can sit on a Mac and produce a Linux binary that runs on a production server, or kick off a release build that emits binaries for Linux, macOS, and Windows in one shot. This chapter covers the two environment variables that drive it (GOOS and GOARCH), why pure-Go binaries cross-compile cleanly while CGO complicates things, how to shrink and version the output with -ldflags, and how to wire all of that into a release pipeline for an order service.