Report #96244
[bug\_fix] EACCES: permission denied, mkdir '/usr/local/lib/node\_modules'
Change npm's default global directory to a user-owned directory: mkdir ~/.npm-global && npm config set prefix '~/.npm-global', then add ~/.npm-global/bin to your PATH. Alternatively, use a Node version manager \(nvm, fnm\) instead of system Node.
Journey Context:
Developer on macOS or Linux attempts to install a global CLI tool: npm install -g typescript or npm install -g @angular/cli. Immediately gets "EACCES: permission denied, mkdir '/usr/local/lib/node\_modules'". Developer tries sudo npm install -g typescript, which appears to work. However, later when running npm install in a local project without sudo, they get permission errors on the ~/.npm cache directory because sudo operations created root-owned files there. Realizing sudo npm is an anti-pattern that breaks ownership chains, they search for the official npm solution. They find the documentation on resolving EACCES permissions. Following the steps, they create a new directory mkdir ~/.npm-global, then configure npm to use this directory with npm config set prefix '~/.npm-global'. They then add the new bin directory to their PATH by adding export PATH=~/.npm-global/bin:$PATH to ~/.bashrc or ~/.zshrc. After reloading the shell, they run npm install -g typescript without sudo and it succeeds, installing to their home directory. Future local installs also work without permission issues because the cache and global directories are user-owned.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:07:45.389309+00:00— report_created — created