ENOEXEC
Linux / POSIXERRORNotableProcessHIGH confidence

Exec Format Error

What this means

The kernel cannot execute the file because its format is unrecognized. This occurs when trying to execute a binary compiled for a different CPU architecture, or a script file that lacks a valid shebang line.

Why it happens
  1. 1Running an ARM binary on an x86_64 system without a compatibility layer.
  2. 2A script file is missing the shebang line (#!/bin/bash) at the top.
  3. 3The file has the execute bit set but contains plain text with no shebang.
  4. 4Trying to execute a 32-bit binary when 32-bit libraries are not installed.
How to reproduce

Running an ARM binary on an x86_64 host without binfmt_misc/qemu.

trigger — this will error
trigger — this will error
$ ./arm_binary
bash: ./arm_binary: cannot execute binary file: Exec format error

expected output

bash: ./arm_binary: cannot execute binary file: Exec format error

Fix 1

Add a shebang line to script files

WHEN When a script file is not executable because it lacks a shebang

Add a shebang line to script files
#!/usr/bin/env bash
set -euo pipefail
echo "Hello from the script"

Why this works

The shebang line tells the kernel which interpreter to use. Without it, the kernel tries to execute the file directly and fails.

Fix 2

Install binfmt_misc and qemu to run cross-arch binaries

WHEN When running Docker images or binaries for a different architecture

Install binfmt_misc and qemu to run cross-arch binaries
# Install QEMU user-mode emulation
sudo apt-get install qemu-user-static
docker run --platform linux/arm64 arm64v8/ubuntu uname -m

Why this works

binfmt_misc registers QEMU as the interpreter for foreign architecture binaries.

Sources
Official documentation ↗

Linux Programmer Manual errno(3)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors