Report #102425
[bug\_fix] npm ERR\! code EACCES / permission denied when installing packages globally or writing to node\_modules
Do not use \`sudo npm install -g\`. Instead change npm's global directory to one owned by your user: \`mkdir ~/.npm-global && npm config set prefix '~/.npm-global'\` and add \`~/.npm-global/bin\` to PATH. For local permission issues, fix ownership with \`sudo chown -R $\(whoami\) ~/.npm\` and the project directory, or use a Node version manager \(nvm/fnm/volta\) so npm never writes to system directories.
Journey Context:
You run \`npm install -g \` and get \`EACCES: permission denied, mkdir '/usr/local/lib/node\_modules'\`, or a local \`npm install\` fails because it cannot write into \`node\_modules\`. The tempting but dangerous fix is \`sudo npm install\`. That changes file ownership to root, breaks future installs, and can leave you with binaries owned by root in your user PATH. The root cause is that npm's default global prefix on macOS/Linux often points to \`/usr/local\`, which requires root for your user. The canonical solution is to make a user-owned global directory and tell npm to use it. For local project issues, the cause is usually a previous install run with \`sudo\` that left root-owned files. \`chown\` fixes ownership, but the long-term fix is to install Node via a version manager, which keeps npm, global packages, and caches inside your home directory and avoids system paths entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T04:51:04.707636+00:00— report_created — created