npm ERR! code EACCES
This error matches known, documented patterns with reliable solutions.
Quick Fix (Most Common Solution)
- Use nvm to manage Node versions
- Change npm default directory ownership
Seeing "npm ERR! code EACCES"? This error can be frustrating, but it's usually fixable. It typically affects your development workflow or system. Below you'll find clear, step-by-step solutions to resolve this issue.
What This Error Means
npm lacks permission to write to the global node_modules directory.
Frequently documented in developer and vendor support forums.
Not affiliated with browser, OS, or device manufacturers.
New here? Learn why exact error messages matter →
Common Causes
- Installing global packages without sudo
- Incorrect npm directory ownership
- Restricted file system permissions
How to Fix
- Use nvm to manage Node versions
- Change npm default directory ownership
- Use sudo npm install -g (not recommended)
Last reviewed: March 2026 How we review solutions
Version note: Most common on Linux systems with Node installed via package manager (apt, yum). Not typically seen with nvm-managed installs.
Environment-Specific Commands
Linux
mkdir -p ~/.npm-globalnpm config set prefix '~/.npm-global'Add export PATH=~/.npm-global/bin:$PATH to ~/.bashrcsource ~/.bashrc
macOS
Install nvm: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashnvm install --ltsnvm use --ltsGlobal installs now work without sudo
Windows
Run terminal as Administrator, orUse nvm-windows: download from github.com/coreybutler/nvm-windowsnvm install ltsnvm use lts
Quick Diagnostic Path
- If Error path contains /usr/lib/node_modules → Change npm prefix: npm config set prefix ~/.npm-global
- If Error path contains ~/.npm or ~/.config → Fix ownership: sudo chown -R $(whoami) ~/.npm ~/.config
- If Error occurs only in CI/CD → Run npm ci --ignore-scripts or add --unsafe-perm flag
If This Still Fails, Check
- After fixing permissions, old global packages may still reference the old directory — reinstall them
- Docker containers running as root: set --unsafe-perm or use a non-root user with correct ownership
- WSL2 users: Windows-mounted drives (/mnt/c/) have fixed permissions — work inside the Linux filesystem instead
Checking and fixing npm directory ownership
# Check current prefix
npm config get prefix
# If /usr/local, change to user-owned directory
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# Verify
npm install -g npm # Should work without sudoOptional follow-up
Some users ask whether saving fixes for recurring errors would be useful when the same issue appears again.
Was this explanation helpful?
Frequently Asked Questions
Why does npm need sudo?
Global installs write to system directories that require elevated permissions by default.
Is using sudo with npm safe?
It can cause permission issues. Using nvm or fixing directory ownership is preferred.
Related Resources
Also Known As
- npm install error
- npm dependency error
- node package manager error
- npm ERR! message
Common Search Variations
- "npm install not working"
- "npm ERR how to fix"
- "node modules error fix"
- "npm install failed what to do"
- "npm dependency conflict solution"
- "why does npm install fail"
Related Errors
Still Stuck?
Paste a different error message or upload a screenshot to get help instantly.