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: June 2026 How we review solutions
Didn't fix it? Get a personalised solution
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 sudoEdge Cases
Three Scenarios Where Standard Eacces Permission Denied Fixes Do Not Work
Eacces Permission Denied handles the common case, but three scenarios require a different approach and are frequently overlooked in documentation.
Monorepo workspaces: In a workspace configuration (npm workspaces, Yarn, pnpm), running npm install from a nested package directory instead of the workspace root causes Eacces Permission Denied — the package manager needs to reconcile all workspace dependencies simultaneously. Always run install commands from the root. Postinstall scripts: Some packages run Node.js scripts during npm install. If those scripts fail (missing binary, wrong Node version), npm reports the failure as Eacces Permission Denied even though the installation itself succeeded. Add --ignore-scripts to test whether a postinstall script is the true cause. Linked packages: If you have used npm link for local development, the linked package's dependencies may conflict with those in the host project, producing Eacces Permission Denied that disappears after npm unlink.Optional 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.