EACCES 📦 npm

npm ERR! code EACCES — permission denied

npm can’t write to a directory — usually global installs into a root-owned folder.

Seen on: npm Linux

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 npm left root-owned files in ~/.npm
  • Project folder owned by another user

⚡ Quick fix

  1. Use a Node version manager (nvm, fnm, volta) so globals live in your home dir
  2. Fix cache ownership: sudo chown -R $(whoami) ~/.npm
  3. Or set a user prefix: npm config set prefix ~/.npm-global
  4. Avoid sudo npm install

Detailed fix by platform

Linux

  1. 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

  1. Path — Which path is denied?
  2. Owner — ls -ld that 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.