Radoslaw Smigielski

19 November 2025

Cross compile Golang for your Raspberry Pi and other platforms

by Radosław Śmigielski

Why?

You probably have your own reason(s) why you need to compile Go code for Raspberry Pi. Maybe you have own project which does not come in binary form from your Raspberry Pi operating system (Raspbian, Ubuntu). In my case, my old Raspberry Pi was too slow to compile Golang.

Environment

Raspbian GNU/Linux 12 (bookworm) on Raspberry Pi Model B Plus Rev 1.2.

Golang cross compilaton

Golang cross comilation is the simplest way of cross compiling code, I’ve ever seen so far ;) It was first added in Golang 1.14 and has become usable in 1.15. It allows to select your target by setting these two variables before you compile your code:

  1. GOOS - target operating system
  2. GOARCH - target compilation architecture

GOOS available options:

  1. android
  2. darwin
  3. dragonfly
  4. freebsd
  5. illumos* - OpenSolaris fork
  6. ios
  7. js - experimental WebAssembly
  8. linux
  9. netbsd
  10. openbsd
  11. plan9
  12. solaris
  13. wasip1** - WebAssembly System Interface
  14. windows

wasip1*) https://github.com/golang/go/issues/58141, https://wasi.dev
illumos**) OpenSolaris fork developed since 2010, after Oracle decided to discontinue OpenSolaris.

GOARCH available options:

  1. 386
  2. amd64
  3. arm
  4. arm64
  5. loong64
  6. mips
  7. mips64
  8. mips64le
  9. mipsle
  10. ppc64
  11. ppc64le
  12. riscv64
  13. s390x
  14. wasm

(!) Not all the combinations of GOARCH and GOOS are supported. Supported combinations can be checked using this command:

go tool dist list

And this is how it looks on my Golang go1.24.10:

aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
freebsd/arm64
freebsd/riscv64
illumos/amd64
ios/amd64
ios/arm64
js/wasm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/loong64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/riscv64
linux/s390x
netbsd/386
netbsd/amd64
netbsd/arm
netbsd/arm64
openbsd/386
openbsd/amd64
openbsd/arm
openbsd/arm64
openbsd/ppc64
openbsd/riscv64
plan9/386
plan9/amd64
plan9/arm
solaris/amd64
wasip1/wasm
windows/386
windows/amd64
windows/arm64

How ?

Finally. After this long into here is how you can compile Go code for different versions of Raspberry Pi:

  1. Check your Raspberry Pi version:
    radek@pi14:~ $ arch
    armv6l
    

    In my case this is ARM v6, in your case may be different.

  2. Set GOARCH and GOOS and compile:
    GOOS=linux GOARCH=arm GOARM=6 go build run.go
    
  3. Check ths produced binary
    $ file run
    run: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, BuildID[sha1]=51d8599ec532368d6923160997a87b4f42d0faba, with debug_info, not stripped
    

Sources

  1. Golang source code
  2. Go all supported platforms definition: src/cmd/dist/build.go
tags: Linux