Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

node fails in WSL with exec format error

Errorzsh: exec format error: node

Short answer

The node that zsh finds is probably a Windows program on the PATH, and is not a Linux program. Check which node runs, install Node.js inside WSL, and keep Windows path entries from shadowing it. Also check that interop has not been turned off, which blocks Windows processes from launching.

  • Applies to WSL 2, Ubuntu 24.04, zsh 5, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See which node zsh resolves. A path under /mnt/c means it is the Windows one.

    which -a node
  2. 2Match what you see, then jump to its fix

    1. 1Windows tools fail too, and node resolves under /mnt/cWindows interop is switched offFix
    2. 2which -a node lists a /mnt/c path before or instead of a Linux oneA Windows PATH entry shadows a Linux Node.jsFix

What does the error look like?

  • zsh: exec format error: node

Cause 1 of 2

Windows interop is switched off

1Check

WSL runs Windows tools as native commands. Interop can be disabled in /etc/wsl.conf, or for one session via binfmt_misc.

cat /etc/wsl.conf
cat /proc/sys/fs/binfmt_misc/WSLInterop

2Fix

Under [interop], enabled=false blocks Windows processes. Set it to true, or better, install Node.js inside WSL.

[interop]
enabled=true

3Verify

Restart WSL, then run a Windows tool and node.

# in PowerShell
wsl --shutdown

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 2

A Windows PATH entry shadows a Linux Node.js

1Check

appendWindowsPath defaults to true, so Windows path elements are added to the Linux PATH.

echo $PATH | tr ':' '\n' | grep mnt

2Fix

Install Node.js inside WSL with nvm, which the project says works through WSL, and put it first.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | bash

3Verify

Open a new terminal; node must resolve to your home folder.

command -v nvm
nvm install --lts
which node

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Install developer tools inside WSL, and keep projects in the Linux filesystem.
  • Check which -a before blaming the binary.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.