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
- Fix global install permissions by changing npm's default directory: mkdir ~/.npm-global && npm config set prefix '~/.npm-global'
- Add the new bin to your PATH: export PATH=~/.npm-global/bin:$PATH (add to ~/.bashrc or ~/.zshrc)
- Fix npm cache permissions: sudo chown -R $(whoami) ~/.npm
- 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.
