Report #16869
[bug\_fix] npm ERR\! code EACCES
Do not use \`sudo npm install -g\`. Instead, change npm's default directory to one owned by your user: \`mkdir ~/.npm-global\`, \`npm config set prefix '~/.npm-global'\`, add \`export PATH=~/.npm-global/bin:$PATH\` to \`~/.bashrc\` or \`~/.zshrc\`, then reload. Alternatively, use a Node version manager \(nvm, fnm\) which handles permissions correctly.
Journey Context:
You try to install a global CLI tool like \`npm install -g typescript\` or \`@angular/cli\`, and immediately hit \`EACCES: permission denied\` on \`/usr/local/lib/node\_modules\`. Your first instinct is to use \`sudo npm install -g\`, which works temporarily but creates a permissions nightmare where future local installs or updates require sudo, and postinstall scripts run as root. The rabbit hole: you research and find the official npm documentation explicitly warns against using \`sudo\` with npm because it bypasses security measures and breaks the ability to safely run package scripts. You learn that npm defaults to installing globals in a system directory owned by root. The solution involves reconfiguring npm to use a user-owned directory \(\`~/.npm-global\`\). You create the directory, set the npm prefix, update your shell's \`PATH\` to look in the new location first, and reload your shell. Global installs now work without sudo and without permission errors. Even better, you discover that using \`nvm\` \(Node Version Manager\) avoids this entirely by installing Node/npm in your home directory, making this issue moot.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:51:43.874145+00:00— report_created — created