node: cannot execute binary file - the four ways Node breaks
node --version failing with cannot execute binary file is almost never a Node bug. It
means the shell found a file called node, asked the kernel to run it, and the kernel
refused — because the file is not a program for this CPU.
Every measurement below was taken on bash 5.3.9 / Linux 7.0 x86-64.
First: is it even the right error?
Two different failures look similar and have nothing in common.
$ node --version
bash: /usr/local/bin/node: cannot execute binary file: Exec format error # rc=126
$ node --version
bash: /usr/local/bin/node: No such file or directory # rc=127
| Message | Exit | Meaning |
|---|---|---|
cannot execute binary file: Exec format error |
126 | The binary is for a different architecture |
No such file or directory (file exists) |
127 | The binary's loader or libc is missing |
command not found |
127 | There is no node on PATH at all |
The middle row is the trap: a glibc build of Node on Alpine (musl) reports
no such file or directory while ls -l $(which node) shows a perfectly good file. It is
the interpreter path inside the binary that does not exist. Measured on Alpine 3.20 with a
glibc binary:
$ docker run --rm -v /bin/true:/x/true:ro alpine:3.20 /x/true
exec /x/true: no such file or directory
How Node specifically gets the wrong architecture
1. Apple Silicon and Docker
node:latest on an M-series Mac is arm64. If that image, or a binary copied out of it,
reaches an x86-64 host, it is unrunnable. The reverse happens just as often: an amd64
image built on a laptop and run on ARM hardware.
docker run --rm --platform linux/amd64 node:22 node -e "console.log(process.arch)"
# ^ force the platform instead of inheriting the host's
2. Copying the binary instead of installing it
Node's official downloads are per-architecture:
node-v22.x-linux-x64.tar.xz, node-v22.x-linux-arm64.tar.xz,
node-v22.x-darwin-arm64.tar.gz. Copying ~/.nvm/versions/node/.../bin/node from one
machine to another copies the architecture with it. Use the package manager or nvm on the
target — that is the only version that is guaranteed to match.
3. A stale nvm or PATH symlink
which node can resolve to a leftover directory from an older install. Node then fails with
an error that has nothing to do with the version you think you are running.
command -v node # which file is actually being executed
ls -l "$(command -v node)" # is it a symlink chain into an old prefix?
4. A wrapper script that points at nothing
A shim in front of Node (some installers do this) fails differently — 127, not 126:
$ node --version
/usr/local/bin/node: line 2: /opt/node/bin/node: No such file or directory # rc=127
If you see 127 with a path inside the message, read the wrapper — the target is gone.
Identify it in two commands
file "$(command -v node)"
# ELF 64-bit LSB executable, ARM aarch64 ... <- arm64 binary on an x86-64 host
# ELF 64-bit LSB executable, x86-64 ... <- architecture is fine; look at libc
readelf -l "$(command -v node)" | grep interpreter
# [Requesting program interpreter: /lib/ld-linux-x86-64.so.2] <- glibc build
# [Requesting program interpreter: /lib/ld-musl-x86_64.so.1] <- musl build
Compare with uname -m. If the machine types differ, you need a different Node build. If
they match, compare the interpreter with what the host actually has.
You can also drop the binary into ELF Inspector — it reads the header locally in the browser and shows class, machine and interpreter on one screen.
Fixes by cause
| Cause | Fix |
|---|---|
| Architecture mismatch | Install Node for the target arch (package manager, nvm, or the matching tarball) |
| Docker platform mismatch | docker run --platform linux/amd64 … or build a multi-arch image |
| glibc build on Alpine | Use the node:alpine image, or install gcompat, or use the official Node linuxmusl build |
| Stale symlink / old prefix | nvm uninstall <old>, or fix PATH; verify with command -v node |
| Wrapper pointing at a removed release | Reinstall; do not patch the wrapper |
What does not help: chmod +x (the file is already executable — the kernel rejected its
contents, not its permissions), sudo (the kernel does not care who runs it), and
copying a loader from another machine (its libraries will not match).
The one-line check to put in CI
Before blaming Node for anything, assert the platform:
node -e "console.log(process.platform, process.arch)" # e.g. linux x64
If Node cannot start at all, use the file check instead:
file "$(command -v node)" | grep -q "$(uname -m)" || { echo "wrong arch"; exit 1; }
Measured on bash 5.3.9 / Linux 7.0 x86-64 and Alpine 3.20. The wrong-architecture case was
produced by patching e_machine in a real x86-64 executable, so the failure is the genuine
kernel ENOEXEC path, not a simulated message.