Report #11979
[bug\_fix] npm ERR\! code EACCES permission denied mkdir '/usr/local/lib/node\_modules'
Change npm's global directory to a user-owned directory: mkdir ~/.npm-global && npm config set prefix '~/.npm-global' && export PATH=~/.npm-global/bin:$PATH, or use a Node version manager \(nvm, fnm\) instead of system Node.
Journey Context:
You just installed Node.js from the Ubuntu apt repository and try to npm install -g typescript. It fails with EACCES permission denied trying to write to /usr/local/lib. You try sudo npm install -g which works but then you read blog posts saying sudo with npm breaks permissions and creates security risks. You consider chown -R $\(whoami\) /usr/local but that feels wrong and might break system updates. You find the official npm documentation on resolving EACCES errors. Following it, you create ~/.npm-global, set npm config set prefix '~/.npm-global', and add that bin to your PATH in .bashrc. Now npm install -g typescript works perfectly without sudo and without touching system directories.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:47:17.639806+00:00— report_created — created