Report #56116
[bug\_fix] npm ERR\! code EACCES: permission denied when installing global packages or writing to cache
Do not use \`sudo\` with npm. Change npm's default directory to one owned by the current user: \`mkdir ~/.npm-global\`, \`npm config set prefix '~/.npm-global'\`, and add \`~/.npm-global/bin\` to PATH. Alternatively, use a Node version manager \(nvm, fnm, volta\) which handles permissions correctly.
Journey Context:
A developer on macOS runs \`sudo npm install -g typescript\` because global installs fail with 'EACCES permission denied'. It works. Later, running \`npm install\` in a local project without sudo fails with 'EACCES' because npm created directories in \`~/.npm\` or \`/usr/local\` owned by root. They try \`sudo chown -R $\(whoami\) ~/.npm\`, which helps temporarily. But the fundamental issue is that the global prefix is system-owned. They follow the npm documentation: create \`~/.npm-global\`, set the prefix config, export the new bin path in \`.zshrc\`, reload the shell, and now \`npm install -g typescript\` works without sudo. Root cause: npm defaults to \`/usr/local\` on many systems which requires root privileges; running npm with sudo creates files owned by root that subsequent non-root npm processes cannot modify.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T00:41:13.915946+00:00— report_created — created