Senior
What is a Go binary, what does it contain, and how to run Go code on multiple platforms?
sobes.tech AI
Answer from AI
Go binary — is a compiled executable file containing:
- Machine code of the program, ready to run on the target platform.
- Built-in Go runtime, including garbage collector, goroutine scheduler, and standard library.
- Debugging information (optional).
Go is compiled into a statically linked binary, which simplifies deployment — no need to install an interpreter or dependencies.
Cross-compilation is used to run Go code on multiple platforms. In Go, this is done by setting environment variables GOOS and GOARCH before compilation:
# Compilation for Windows 64-bit
GOOS=windows GOARCH=amd64 go build -o app.exe
# Compilation for Linux ARM
GOOS=linux GOARCH=arm go build -o app
Thus, you can build binaries for different operating systems and architectures from a single development machine.
The full list of supported platforms can be obtained with the command:
go tool dist list