Go shines in developing cross-platform programs. It makes building for multiple platforms without changing the program’s source code effortless. We can write code once and build it for major operating systems. We need only set these environment variables when building our programs:
GOOS
—Sets the target operating systemGOARCH
—Sets the target machine’s architecture
The variables are set to the current machine’s configuration by default:
$ go env GOOS GOARCH darwin arm64 #1
Let’s list all the operating systems and architectures for which we can compile:
$ go tool dist list aix/ppc64 freebsd/riscv64 linux/mips64le openbsd/arm android/386 illumos/amd64 linux/mipsle openbsd/arm64 android/amd64 ios/amd64 linux/ppc64 openbsd/ppc64 android/arm ios/arm64 linux/ppc64le plan9/386 android/arm64 js/wasm linux/riscv64 plan9/amd64 darwin/amd64 linux/386 linux/s390x plan9/arm darwin/arm64 linux/amd64 netbsd/386 solaris/amd64 dragonfly/amd64 linux/arm netbsd/amd64 wasip1/wasm freebsd/386 linux/arm64 netbsd/arm windows/386 freebsd/amd64 linux/loong64 netbsd/arm64 windows/amd64 freebsd/arm linux/mips openbsd/386 windows/arm freebsd/arm64 linux/mips64 openbsd/amd64 windows/arm64