Executing compiled command-line applications, custom utility binaries, or shell automation scripts is the core of working in the Linux terminal. However, running a downloaded binary with ./app only to be halted by the error message bash: ./app: cannot execute binary file: Exec format error (kernel error code ENOEXEC) prevents software execution. This error indicates that the Linux kernel cannot parse the binary file’s ELF header or that the binary was compiled for an incompatible CPU architecture.
Why Linux Returns “Exec format error”
The Linux kernel’s binary loader reads the initial bytes of any executable file before creating a process:
- CPU Architecture Mismatch: Attempting to run an ARM64 (aarch64) binary on an x86_64 Intel/AMD processor, or running an x86_64 binary on a Raspberry Pi or Apple Silicon Linux VM.
- 32-Bit vs 64-Bit Incompatibility: Running a 32-bit executable on a 64-bit Linux distribution that lacks 32-bit multiarch runtime libraries.
- Missing or Malformed Shebang in Shell Scripts: A shell or Python script marked executable (
chmod +x) lacking the interpreter line (#!/usr/bin/env bash) at byte 0. - Corrupted or Incomplete File Download: A truncated binary file download missing standard ELF (Executable and Linkable Format) magic headers.
- Windows PE/EXE Binary Executed on Linux: Attempting to run a native Windows
.exefile without an emulator like Wine.
1. Identify Architecture of the Binary vs System CPU
Comparing the compiled architecture of the file against your physical processor pinpoints mismatches immediately.
- Check your system’s CPU architecture:
(Common outputs:uname -mx86_64for Intel/AMD 64-bit;aarch64orarmv7lfor ARM). - Check the architecture of the problematic binary using the
filecommand:file ./app - Examine the output:
- If
uname -mreturnsx86_64butfile ./appsaysELF 64-bit LSB executable, ARM aarch64, you downloaded the wrong CPU build. - Download the corresponding x86_64 (amd64) release from the vendor’s repository.
- If
2. Fix Missing or Broken Shebang in Shell Scripts
If the file is a text-based script, the kernel requires a valid shebang line to select the interpreter.
- Open the script with a text editor:
nano ./script.sh - Verify that the very first line contains a valid interpreter path:
(For Python scripts:#!/usr/bin/env bash#!/usr/bin/env python3). - Ensure there are no blank lines or spaces before the shebang.
- Check for Windows DOS line endings (CRLF) using
dos2unix:dos2unix ./script.sh - Save the file, reapply execution permissions (
chmod +x ./script.sh), and run it.
3. Enable 32-Bit Multiarch Support (Debian/Ubuntu)
Modern 64-bit Linux systems require 32-bit architecture packages to execute legacy 32-bit binaries.
- If
file ./appreportsELF 32-bit LSB executable, Intel 80386:sudo dpkg --add-architecture i386 sudo apt update sudo apt install libc6:i386 libncurses5:i386 libstdc++6:i386 -y - Once multiarch compatibility libraries are installed, re-run the 32-bit application.
4. Verify File Integrity and Re-download
Incomplete downloads corrupt ELF magic numbers (0x7F 'E' 'L' 'F').
- Inspect the top 4 bytes of the binary:
head -c 4 ./app | xxd - The output should start with
7f45 4c46. If it starts with HTML or error text (e.g.<!DO), your download tool received a web error page rather than the actual binary. - Re-download the file directly using
wget -O app <URL>orcurl -L -O <URL>.
5. Run Windows Binaries via Wine
If the file is a native Windows PE32 executable, Linux cannot execute it natively.
- Install Wine:
sudo apt install wine -y - Execute the program through the Wine translation layer:
wine ./app.exe