Report #104326
[bug\_fix] npm ERR\! code EACCES, permission denied \(global install\)
Use a version manager like nvm to avoid global permissions, or change npm's default directory: \`npm config set prefix ~/.npm-global\` and add that to PATH.
Journey Context:
I tried to install a package globally with \`npm install -g\` on a fresh Linux machine and got EACCES errors. I immediately tried \`sudo npm install -g\` which worked but created permission headaches later. After researching, I learned the recommended approach is to avoid sudo by configuring npm to use a user-owned directory. I set \`npm config set prefix ~/.npm-global\` and added \`export PATH=~/.npm-global/bin:$PATH\` to my .bashrc. Now global installs work without sudo. The root cause: npm's default global directory is \`/usr/local/lib/node\_modules\` owned by root, so non-root users can't write there. The fix moves the global directory to the user's home.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-02T20:04:11.523593+00:00— report_created — created