npm ERR! code EACCES — permission denied
npm can’t write to a directory — usually global installs into a root-owned folder.
Meaning
Installing globally (npm i -g) with a system Node puts packages in /usr/local/lib/node_modules, owned by root. Using sudo makes it worse (root-owned cache files).
Common causes
- Global install into root-owned prefix
- Previous
sudo npmleft root-owned files in ~/.npm - Project folder owned by another user
⚡ Quick fix
- Use a Node version manager (nvm, fnm, volta) so globals live in your home dir
- Fix cache ownership:
sudo chown -R $(whoami) ~/.npm - Or set a user prefix:
npm config set prefix ~/.npm-global - Avoid
sudo npm install
Detailed fix by platform
Linux
- User-level global prefix:bash
mkdir -p ~/.npm-global npm config set prefix ~/.npm-global echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc && source ~/.bashrc
How to diagnose
- Path — Which path is denied?
- Owner —
ls -ldthat path
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026