Report #54855
[bug\_fix] npm ERR\! code EACCES npm ERR\! syscall rename npm ERR\! path /usr/local/lib/node\_modules/@angular/cli npm ERR\! Error: EACCES: permission denied, rename '/usr/local/lib/node\_modules/...'
Do not use sudo npm install -g. Instead, change npm's default directory to one owned by the current user: mkdir ~/.npm-global && npm config set prefix '~/.npm-global' && export PATH=~/.npm-global/bin:$PATH \(add to shell config\). Alternatively, use a Node version manager like nvm, fnm, or volta which handle global package installation in user space without touching /usr/local.
Journey Context:
A developer on macOS or Linux tries to install a global CLI tool like @angular/cli or typescript using npm install -g @angular/cli. The command fails with EACCES permission denied errors referencing /usr/local/lib/node\_modules. The developer assumes they need root access and retries with sudo npm install -g. This appears to work, but later they experience strange permission errors with npm cache or updating packages. They search for the error and find the official npm documentation explicitly warning against using sudo with npm because it creates security risks and ownership issues. They learn that npm defaults to the system /usr/local directory for global installs, which requires root. The solution is to change npm's prefix to a directory in their home folder \(~/.npm-global\) and add it to PATH, or better, to install nvm \(Node Version Manager\) which isolates Node installations entirely within the user's home directory, eliminating permission issues entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:34:12.080894+00:00— report_created — created