Fix npm that fails with permission
We'll check the error, fix ownership of npm dirs, clear the cache, and use npx when needed—or tell you when to escalate.
What you'll need
- Terminal access
- sudo (to fix ownership)
Step-by-step diagnostic
Quick triage — pick your path
Get started
Choose the option that matches what you see. You can jump straight to that section.
- Follow this guide Work through the full procedure.
- Fix ownership You see EACCES and want to fix npm cache or Node dir ownership.
- Clear cache The cache may be corrupted or have bad permissions.
- Use npx You need to run a package without global install.
- When to escalate You cannot fix ownership or the error persists.
Show full guide
Steps
Goal: Fix npm permission errors by correcting ownership, clearing the cache, or using npx.
- Check the error message. EACCES means npm cannot write to a directory—often ~/.npm, the global modules dir, or project node_modules.
- Good: You see EACCES or “permission denied.” Proceed to Fix ownership.
- Bad: Different error (ENOENT, network)—see a different guide.
Fix ownership
Goal: Correct ownership of the npm cache and Node install directory.
- Run
sudo chown -R $(whoami) ~/.npm. The npm cache lives in ~/.npm. Wrong ownership often comes from running npm with sudo. - If you use nvm:
sudo chown -R $(whoami) ~/.nvm. If Node is in /usr/local:sudo chown -R $(whoami) /usr/local/lib/node_modules /usr/local/bin. - Retry the npm command. Confirm you should see the command succeed.
- Bad: Still fails—proceed to Clear cache.
Clear cache
Goal: Remove a corrupted or permission-broken npm cache.
- Run
npm cache clean --force. Retry the original command. - Confirm you should see the command succeed or a different error.
- Bad: Still fails—check
npm config get prefix. If it points to /usr/local or another system dir, set a user prefix:npm config set prefix ~/.npm-globaland add ~/.npm-global/bin to PATH.
Use npx
Goal: Run packages without global install when you lack write access.
- Use npx instead of
npm install -g:npx <package>runs the package without installing it globally. - Example:
npx create-react-app my-app. Confirm you should see the package run. - Good: npx works for your use case. Bad: You need a persistent global install and cannot fix ownership—escalate.
When to get help
Escalate if:
- You cannot change ownership (shared system, corporate policy).
- The error persists after fixing ownership and clearing the cache.
- You need a global install and npx is not sufficient.
Provide the full error, npm config list, and ls -la of the failing path.
Verification
- The npm command that failed now runs without EACCES or permission errors.
npm installornpm install -gcompletes successfully.- No need to use sudo for npm commands.
Escalation ladder
Work from the device outward. Stop when the problem is fixed.
- Fix ownership chown -R on ~/.npm and Node install dir.
- Clear cache npm cache clean --force.
- Use npx or user prefix npx for one-off runs; set prefix to ~/.npm-global.
- Escalate Provide error, npm config list, ls -la of failing path.
What to capture if you need help
Before calling support or posting for help, have these ready. It speeds everything up.
- Full error message and failing path
- npm config get prefix and globaldir
- ls -la of ~/.npm and Node install dir
- Steps already tried
Does the error mention EACCES or permission denied?
Read the full error. EACCES means npm cannot write to a directory.
You can change your answer later.
Can you fix ownership of ~/.npm and the Node dir?
chown -R fixes wrong ownership from sudo npm or mixed installs.
You can change your answer later.
Does npm work after fixing ownership?
Retry the original npm command.
You can change your answer later.
Clear cache and retry
Can you use npx instead of global install?
npx runs packages without installing them globally.
You can change your answer later.
Resolved
Escalate
Different error
Reviewed by Blackbox Atlas
Frequently asked questions
- Why does npm fail with EACCES?
- npm cannot write to its cache (~/.npm), global modules dir, or project node_modules. Wrong ownership, running as root then as user, or a corrupted cache. Fix ownership with chown.
- Can I fix npm permission errors myself?
- Yes. Run chown on ~/.npm and the Node install dir. Use npm cache clean --force. Use npx instead of global install when you lack write access. Do not use sudo npm.
- When should I escalate npm permission issues?
- If you cannot change ownership (shared system, corporate policy), or the error persists after fixing ownership and clearing the cache. Provide the full error and npm config list output.
Rate this guide
Was this helpful?
Thanks for your feedback.