Fix "npm ERR! code EACCES: permission denied" on macOS & Linux
Occurs when npm attempts to install packages into system directories (/usr/local/lib or /usr/lib) owned by root, without proper user write permissions.
npm ERR! code EACCES / syscall access / permission denied
Quick Fix Checklist
- Best practice: Install and manage Node via NVM (Node Version Manager) or Volta
- Alternative: Configure npm to install global packages in your home directory
- Run: mkdir ~/.npm-global && npm config set prefix '~/.npm-global'
- Add export PATH=~/.npm-global/bin:$PATH to your ~/.bashrc or ~/.zshrc