Report #84631
[bug\_fix] EACCES: permission denied, mkdir '/usr/local/lib/node\_modules'
Change npm's default directory to one owned by the current user: \`mkdir ~/.npm-global\`, \`npm config set prefix '~/.npm-global'\`, then add \`~/.npm-global/bin\` to the PATH \(e.g., \`export PATH=~/.npm-global/bin:$PATH\` in \`~/.bashrc\`\). Do not use \`sudo\` with npm.
Journey Context:
Developer on macOS or Linux attempts to install a package globally, e.g., \`npm install -g @angular/cli\` or \`npm install -g typescript\`. The command fails with \`EACCES: permission denied, mkdir '/usr/local/lib/node\_modules/@angular'\`. Developer attempts to fix with \`sudo npm install -g\`, which appears to work but causes subsequent permission issues \(npm cache owned by root, subsequent local installs breaking\). Developer tries \`sudo chown -R $\(whoami\) /usr/local\`, which can break Homebrew or other tools expecting specific permissions on \`/usr/local\`. Eventually, the developer reads the npm documentation on resolving EACCES errors, which explains that npm's default prefix in \`/usr/local\` requires root on many systems. The recommended solution is to change npm's prefix to a user-writable directory \(\`~/.npm-global\`\), eliminating the need for sudo entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:38:43.874328+00:00— report_created — created