Building Go Applications for Different Operating Systems and Architectures On One Computer.
To run a build for a different platform, we simply set the GOOS
and GOARCH
environment variables (for the operating system and architecture, respectively) and invoke "go build"
When you run a command like go build
, Go uses the current platform’s GOOS
and GOARCH
to determine how to build the binary. To find out what combination your platform is, you can use the go env
command and pass GOOS
and GOARCH
as arguments:
go env GOOS GOARCH
If you are not using a Windows system, build a windows
binary of app
by setting the GOOS
environment variable to windows
when running the go build
command:
GOOS=windows go build
To find this list of possible platforms, run the following:
go tool dist list
A list of GOOS/GOARCH supported by go
out of the box
darwin/386
darwin/amd64
linux/386
linux/amd64
linux/arm
linux/arm64
windows/386
windows/amd64