Report #99593
[bug\_fix] npm ERR\! code EACCES permission denied when installing packages globally
Do not install global packages with \`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' && export PATH=~/.npm-global/bin:$PATH\` \(add the export to ~/.bashrc or ~/.zshrc\). Alternatively, use a Node version manager such as nvm, fnm, or volta, which avoid global permission issues entirely.
Journey Context:
You run \`npm install -g typescript\` and npm spews "EACCES: permission denied, mkdir '/usr/local/lib/node\_modules'". Your first instinct is \`sudo npm install -g typescript\`, which works but breaks file ownership and eventually causes every global install to require sudo. You read npm's official permissions guide and learn that npm's default global prefix is a system directory. You create \`~/.npm-global\`, set npm's prefix there, add its bin directory to PATH, and reinstall TypeScript without sudo. From then on global tools install cleanly, and you no longer risk root-owned files in node\_modules.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-30T04:43:49.739884+00:00— report_created — created