Report #16713
[bug\_fix] npm ERR\! code EACCES npm ERR\! syscall mkdir npm ERR\! path /usr/local/lib/node\_modules/package-name npm ERR\! errno -13
Do NOT use sudo. Instead, change npm's default directory to one you own: mkdir ~/.npm-global && npm config set prefix '~/.npm-global' && export PATH=~/.npm-global/bin:$PATH \(add to ~/.bashrc\). Root cause: npm defaults to installing global packages in system directories \(/usr/local\) requiring root permissions, but running npm with sudo creates files owned by root that break subsequent local runs.
Journey Context:
You try to install a CLI tool globally with npm install -g @angular/cli. The command fails with EACCES, permission denied to /usr/local/lib/node\_modules. You think 'I need sudo' and run sudo npm install -g. It appears to work, but now every time you use ng, it asks for password, or worse, cache files become owned by root. Later, local npm install fails with strange permission errors. You research and find the npm documentation warning never to use sudo. You create a local directory ~/.npm-global, tell npm to use it as the prefix, and add it to your PATH. Now global installs work without sudo because the directory is in your home folder, avoiding system directories entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:20:59.212506+00:00— report_created — created