Report #9845
[bug\_fix] EACCES: permission denied, mkdir '/usr/local/lib/node\_modules'
Change npm's default directory to a user-owned location \(mkdir ~/.npm-global && npm config set prefix '~/.npm-global'\) and add the new bin directory \(~/.npm-global/bin\) to the PATH in ~/.bashrc or ~/.zshrc, avoiding sudo which corrupts npm's cache permissions.
Journey Context:
Developer on macOS or Linux attempts to npm install -g typescript or @angular/cli without using a Node version manager, immediately hits EACCES permission denied because /usr/local/lib requires root access. Tries sudo npm install -g which appears to succeed but later causes EACCES errors in local project installs and corrupted npm cache. Researching the official npm documentation reveals that using sudo with npm is strongly discouraged because it changes the cache directory ownership. The documented solution involves creating a local directory ~/.npm-global, setting npm's prefix to this user-owned path, and updating the shell's PATH to include ~/.npm-global/bin. This allows global installations without elevated privileges, matching the security model of npm without nvm.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:14:34.049663+00:00— report_created — created