How to fix npm ERR! code EACCES npm ERR! cannot execute binary file in npm

npmINTERMEDIATEMEDIUMUpdated Dec 3, 2025ยท 197 views

The EACCES error occurs when npm cannot execute a binary due to insufficient permissions. This commonly happens after using sudo with npm or when file ownership is incorrect.

Quick fix

Fixes npm ERR! code EACCES npm ERR! cannot execute binary file

# Fix project node_modules
sudo chown -R $(whoami) node_modules

# Fix global npm directories
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin
  1. Fix node_modules ownership
  2. Delete and reinstall node_modules
  3. Configure npm to use local directory
  4. Use nvm (recommended long-term fix)
npm โ€” error
# Fix project node_modules
sudo chown -R $(whoami) node_modules
# Fix global npm directories
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin
npm ERR! code EACCES
npm ERR! cannot execute binary file

What this error means

This error indicates npm tried to execute a binary file but lacks the necessary permissions. On Unix-like systems (Linux, macOS), files need the execute bit set and the user needs appropriate ownership/group membership to run them. The most common cause is using `sudo npm install` which creates files owned by root. When you later try to run npm commands as a regular user, you can't access or execute root-owned files. This can also occur when transferring node_modules between different operating systems (Windows to Linux) where Unix permissions aren't preserved.

Typical symptoms

  • npm scripts fail with permission denied
  • Cannot run installed CLI tools
  • Error after moving project between systems
  • Works with sudo but fails without

Common causes

  1. Previously ran npm with sudo
  2. node_modules owned by root instead of user
  3. Files transferred from Windows lack execute bit
  4. npm global directory has wrong permissions
  5. Antivirus blocking execution

How to fix "npm ERR! code EACCES npm ERR! cannot execute binary file"

1Fix node_modules ownership

Change ownership to your user:

bash
# Fix project node_modules
sudo chown -R $(whoami) node_modules

# Fix global npm directories
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin

Then retry your npm command without sudo.

2Delete and reinstall node_modules

Clean reinstall often fixes permission issues:

bash
rm -rf node_modules package-lock.json
npm install

Important: Do NOT use sudo for npm install.

3Configure npm to use local directory

Avoid system directories entirely:

bash
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global

Add to ~/.bashrc or ~/.zshrc:

bash
export PATH=~/.npm-global/bin:$PATH

Reload shell and reinstall global packages.

4Use nvm (recommended long-term fix)

Node Version Manager installs to your home directory, avoiding all permission issues:

bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc

nvm install 20
nvm use 20

# Now npm works without sudo
npm install -g some-package
5Fix execute permissions

If files exist but lack execute bit:

bash
# Make all .bin files executable
chmod +x node_modules/.bin/*

# Or for specific binary
chmod +x node_modules/.bin/webpack

Advanced notes

Never do this:

bash
sudo npm install  # Creates root-owned files
chmod 777 node_modules  # Security vulnerability

Best practices:
1. Use nvm to manage Node.js - avoids system directories
2. Never use sudo with npm
3. Configure npm prefix to user directory
4. Use npx for one-off commands instead of global installs

For Docker, run as non-root user:

dockerfile
RUN chown -R node:node /app
USER node

Frequently asked questions

What does "npm ERR! code EACCES npm ERR! cannot execute binary file" mean?
This error indicates npm tried to execute a binary file but lacks the necessary permissions. On Unix-like systems (Linux, macOS), files need the execute bit set and the user needs appropriate ownership/group membership to run them. The most common cause is using sudo npm install which creates files owned by root.
How do I fix "npm ERR! code EACCES npm ERR! cannot execute binary file"?
The EACCES error occurs when npm cannot execute a binary due to insufficient permissions. This commonly happens after using sudo with npm or when file ownership is incorrect.
What causes "npm ERR! code EACCES npm ERR! cannot execute binary file"?
Previously ran npm with sudo node_modules owned by root instead of user Files transferred from Windows lack execute bit
Is the "npm ERR! code EACCES npm ERR! cannot execute binary file" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading