Report #85743
[bug\_fix] npm ERR\! code EACCES ... Permission denied ... /usr/local/lib/node\_modules
Do not use sudo with npm. Instead, change npm's default directory to a user-owned directory \(e.g., ~/.npm-global\) and add it to PATH, or better, use a Node version manager \(nvm, fnm\) to install Node and npm entirely within the user space, avoiding system directories.
Journey Context:
A developer on macOS or Linux installs Node.js using the official installer or system package manager, which places Node in a system directory like /usr/local. They attempt to install a package globally using npm install -g . The command fails with EACCES, stating permission denied to write to /usr/local/lib/node\_modules. They try using sudo npm install -g, which appears to work but changes the ownership of npm's cache and config directories to root, causing subsequent local npm operations to fail with permission errors. Reading the npm documentation on resolving EACCES errors, they learn that npm should never be run with sudo. The recommended solution is to change npm's global directory to one the user owns \(e.g., mkdir ~/.npm-global; npm config set prefix '~/.npm-global'; export PATH=~/.npm-global/bin:$PATH\) or, preferably, uninstall the system Node and use a version manager like nvm or fnm, which installs Node in the user's home directory, completely eliminating permission issues with global packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:30:22.730694+00:00— report_created — created