Skip to content
Latchkey

Go "exec format error" running a cross-compiled binary in CI

The kernel refused to run the binary because its machine format does not match the host. A Go binary cross-compiled for, say, linux/arm64 cannot run on a linux/amd64 runner.

What this error means

A step that runs a freshly built Go binary fails with "exec format error" or "cannot execute binary file: Exec format error", usually after a cross-compile build.

Terminal
./bin/app: cannot execute binary file: Exec format error

Common causes

GOARCH or GOOS does not match the runner

The build set GOARCH=arm64 (or another target) but the job runs the binary on an amd64 Linux runner, which cannot execute it.

A multi-arch image mismatch

The binary was built for one architecture and copied into an image or runner of another, so exec fails at runtime.

How to fix it

Build for the platform that runs it

  1. Decide whether you want to run the binary in CI or only release it.
  2. For a binary you run, build with the runner GOOS/GOARCH (the defaults).
  3. For a release artifact, build the cross target but do not execute it on the runner.
Terminal
# build for the runner so it can run here
go build -o bin/app ./cmd/app
./bin/app --version

Run foreign binaries under emulation

To run a cross-built binary on the runner, register QEMU emulation (for example via docker/setup-qemu-action) before executing it.

.github/workflows/ci.yml
- uses: docker/setup-qemu-action@v3

How to prevent it

  • Separate "build and run here" jobs from "cross-compile for release" jobs.
  • Only set GOOS/GOARCH when producing artifacts you will not execute locally.
  • Use QEMU when a foreign-arch binary genuinely must run in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →