Report #100073
[bug\_fix] npm ERR\! code EACCES — permission denied when installing a package globally
Do not run \`sudo npm install -g\`. Instead change npm's default directory to one you own: \`mkdir ~/.npm-global && npm config set prefix '~/.npm-global'\`, then add \`~/.npm-global/bin\` to your PATH. Alternatively, use a Node version manager such as nvm, fnm, or volta, which manages global packages in user space. The root cause is that the default global prefix lives in \`/usr/local\` or \`/usr/lib\`, which requires root to write.
Journey Context:
You run \`npm install -g typescript\` and npm throws \`EACCES: permission denied, mkdir '/usr/local/lib/node\_modules'\`. You try \`sudo npm install -g typescript\`, which works but later breaks \`npm update\` and file ownership across the system. You read the npm docs and learn that npm historically recommended \`sudo\`, but that changes permissions on system directories and causes recurring permission pain. Changing the global prefix to a directory in your home folder, or switching to nvm, installs globals without elevated privileges and avoids the ownership mess entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-01T04:36:46.834860+00:00— report_created — created