Sometimes I need to cross compile something on my PC to run on a Raspberry Pi. It's really handy that Go has cross compilation built in, it would be even better if I could remember the right environment variables to use whenever I needed to build stuff. It should be easy to remember them, they are.

For 32-bit ARM:

GOOS=linux GOARCH=arm go build

And for 64-bit ARM:

GOOS=linux GOARCH=arm64 go build

I also recently found out you can get a list of supported targets using the command:

go tool dist list

which will output all the OS / ARCH options your current Go installation recognises.

Previous Post Next Post