ProjectStack
npm

npm ERR! code EACCES — permission denied

npm doesn't have write permission to the directory it's trying to install into. This commonly happens when global packages are installed to a system directory that requires root access.

Common causes

  • Installing a global package (-g) to /usr/local/lib which is owned by root
  • npm's cache directory has incorrect permissions
  • You previously ran npm with sudo which changed ownership of npm directories
  • The node_modules folder in your project is owned by a different user

How to fix it

  1. Fix global install permissions by changing npm's default directory: mkdir ~/.npm-global && npm config set prefix '~/.npm-global'
  2. Add the new bin to your PATH: export PATH=~/.npm-global/bin:$PATH (add to ~/.bashrc or ~/.zshrc)
  3. Fix npm cache permissions: sudo chown -R $(whoami) ~/.npm
  4. Avoid using sudo with npm — it causes more permission problems down the line

Example

npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules'

Running npm install -g <package> without the necessary write permissions

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.