How to fix npm ERR! code EACCESSDENIED npm ERR! Access denied in npm

npmBEGINNERMEDIUMUpdated Dec 6, 2025· 366 views

Access denied errors in npm typically stem from file permission issues when installing global packages or writing to node_modules. Use nvm for Node.js management, configure a user-writable npm prefix, or fix directory ownership.

Quick fix

Fixes EACCES

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

# Open new terminal, then:
nvm install --lts
nvm use --lts
  1. Use nvm instead of system Node.js
  2. Fix local project permissions
  3. Configure npm to use home directory
  4. Fix npm cache ownership
npm — error
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Open new terminal, then:
nvm install --lts
nvm use --lts
npm ERR! code EACCESSDENIED
npm ERR! Access denied

What this error means

This error indicates npm cannot read from or write to a directory it needs access to. The most common scenario is trying to install global packages without proper permissions to /usr/local/lib/node_modules. On Unix-like systems, the global npm directory is typically owned by root, while npm runs as your user. On Windows, similar issues occur when npm tries to write to protected directories or when antivirus software blocks file operations. The error can also occur with local installations if your project's node_modules directory has incorrect ownership—often from previously running npm with sudo.

Typical symptoms

  • EACCES: permission denied during npm install
  • Access denied when installing global packages
  • Cannot create directory in /usr/local/lib/node_modules
  • Local npm install fails with permission errors
  • Works with sudo but creates more problems later
  • Error occurs on first npm operation after Node.js installation
  • Antivirus blocks npm operations on Windows

Common causes

  1. Global npm directories owned by root
  2. Previous sudo npm use created root-owned files
  3. Node.js installed with system package manager as root
  4. Local node_modules has wrong ownership
  5. Windows antivirus or security software blocking npm
  6. VSCode or other editors locking files during installation
  7. WSL file permission mismatches

How to fix "npm ERR! code EACCESSDENIED npm ERR! Access denied"

1Use nvm instead of system Node.js

The recommended long-term solution is using nvm:

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

# Open new terminal, then:
nvm install --lts
nvm use --lts

nvm keeps everything in ~/.nvm, avoiding permission issues entirely.

2Fix local project permissions

If the error is in your project's node_modules:

bash
# Change ownership to your user
sudo chown -R $(whoami) node_modules

# Or remove and reinstall
rm -rf node_modules package-lock.json
npm install
3Configure npm to use home directory

Set up npm to install global packages in your home folder:

bash
npm config set prefix ~/.local
echo 'export PATH=~/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

This avoids needing to modify system directories.

4Fix npm cache ownership

If errors reference the npm cache:

bash
sudo chown -R $(whoami) ~/.npm
npm cache clean --force
5Windows: check antivirus and close editors

On Windows, access denied often comes from:

1. Antivirus: Temporarily disable real-time scanning and retry
2. Open editors: Close VSCode, WebStorm, or other IDEs that might lock files
3. Terminal: Run Command Prompt or PowerShell as Administrator (for one-time fixes only)

Clear npm cache after:

powershell
npm cache clean --force
6WSL: avoid mounted Windows paths

In WSL, permission issues are common when working in /mnt/c/:

bash
# Move project to WSL filesystem
mv /mnt/c/project ~/project
cd ~/project
rm -rf node_modules
npm install

The Linux filesystem in WSL handles permissions correctly, unlike mounted Windows drives.

Advanced notes

Why sudo npm is dangerous:

1. Security risk: npm runs package scripts during installation. Running as root means those scripts have root access.
2. Permission cascade: Creates root-owned files that require sudo for all future operations.
3. Breaks user installs: Mixing sudo and non-sudo npm corrupts permissions.

If you've already used sudo npm, the fix is to:
1. Remove node_modules: sudo rm -rf node_modules
2. Fix global directory ownership or switch to nvm
3. Never use sudo with npm again

For CI/CD:

If you see access denied in CI pipelines:
- Ensure the CI user has write access to the workspace
- Don't run npm as root in Docker
- Use npm ci instead of npm install for cleaner installs
- Check that previous pipeline steps didn't change permissions

Frequently asked questions

What does "EACCES" mean?
This error indicates npm cannot read from or write to a directory it needs access to. The most common scenario is trying to install global packages without proper permissions to /usr/local/lib/node_modules. On Unix-like systems, the global npm directory is typically owned by root, while npm runs as your user.
How do I fix "EACCES"?
Access denied errors in npm typically stem from file permission issues when installing global packages or writing to node_modules. Use nvm for Node.js management, configure a user-writable npm prefix, or fix directory ownership.
What causes "EACCES"?
Global npm directories owned by root Previous sudo npm use created root-owned files Node.js installed with system package manager as root
Is the "EACCES" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading