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.
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.
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/webpackNever 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 nodenpm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm