Report #90321
[bug\_fix] npm ERR\! code EACCES ... permission denied, mkdir '/usr/local/lib/node\_modules'
Configure npm to use a custom global directory owned by the user \(mkdir ~/.npm-global && npm config set prefix '~/.npm-global'\) and ensure ~/.npm-global/bin is in PATH, instead of using sudo.
Journey Context:
You attempt npm install -g typescript on a fresh macOS or Linux machine. It fails with EACCES, permission denied to /usr/local/lib. You recall using sudo for such tasks and run sudo npm install -g typescript. It succeeds but now the global node\_modules are owned by root. Later, when running npm update, you get permission errors. You find the npm documentation on fixing EACCES which recommends never using sudo. You create a local .npm-global directory, set npm prefix, add to PATH in .zshrc, and reinstall the global packages without sudo. Future installs work without permission issues.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:11:52.655496+00:00— report_created — created