How to fix npm ERR! code EACCES npm ERR! cannot execute binary file in npm
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- Fix node_modules ownership
- Delete and reinstall node_modules
- Configure npm to use local directory
- Use nvm (recommended long-term fix)
# Fix project node_modulessudo chown -R $(whoami) node_modules# Fix global npm directoriessudo chown -R $(whoami) ~/.npmsudo chown -R $(whoami) /usr/local/lib/node_modulessudo chown -R $(whoami) /usr/local/binnpm ERR! code EACCESnpm 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
- Previously ran npm with sudo
- node_modules owned by root instead of user
- Files transferred from Windows lack execute bit
- npm global directory has wrong permissions
- Antivirus blocking execution
How to fix "npm ERR! code EACCES npm ERR! cannot execute binary file"
Change ownership to your user:
# 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/binThen retry your npm command without sudo.
Clean reinstall often fixes permission issues:
rm -rf node_modules package-lock.json
npm installImportant: Do NOT use sudo for npm install.
Avoid system directories entirely:
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-globalAdd to ~/.bashrc or ~/.zshrc:
export PATH=~/.npm-global/bin:$PATHReload shell and reinstall global packages.
Node Version Manager installs to your home directory, avoiding all permission issues:
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-packageIf files exist but lack execute bit:
# Make all .bin files executable
chmod +x node_modules/.bin/*
# Or for specific binary
chmod +x node_modules/.bin/webpackAdvanced notes
Never do this:
sudo npm install # Creates root-owned files
chmod 777 node_modules # Security vulnerabilityBest 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:
RUN chown -R node:node /app
USER nodeFrequently 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
- ๐npm Official Documentation
- ๐Docs: NPM folders and permissions(Official Docs)
- ๐ฌSO: npm permission denied errors(Stack Overflow)
- ๐GitHub: npm permission issues(GitHub)