npm cannot write to the global prefix because it is root-owned or locked. Move globals into your home (nvm/user prefix) or realign ownership once, then reinstall cleanly.
npm installs global packages into the prefix directory (default /usr/local/lib/node_modules) and links executables under prefix/bin. When those directories are owned by root or mounted read-only, a normal user cannot create or modify files, so npm aborts early with EACCES instead of leaving partially written packages. The issue appears when system Node was installed with sudo or a package manager, when prior sudo npm installs left root-owned artifacts, or when running inside Docker/CI as a non-root user against a root-owned filesystem. Windows/WSL users can also hit it if Defender or corporate EDR blocks writes to node_modules.
npm config get prefix
ls -ld $(npm config get prefix)/{lib/node_modules,bin}Confirm whether the prefix and bin are root-owned or read-only.
# nvm example
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \ . "$NVM_DIR/nvm.sh"
nvm install --lts
# fallback user prefix
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"Keep the PATH export in your shell profile so globals resolve.
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging $(npm config get prefix)/lib/node_modules/.*.DELETE 2>/dev/null || true
npm cache clean --forceRemoves root-owned temp folders that block retries.
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}Do this only on machines you control; avoid on shared hosts.
npm install -g <package>Run with the user-owned prefix so npm can write normally.
If you see EPERM/EACCES on Windows paths, close VS Code/terminals that hold node_modules, add a Defender exclusion for your global prefix, and retry from an elevated PowerShell or with Developer Mode enabled for symlinks.
In Docker/CI, either run npm as the image owner (often root) or set a user prefix inside the workspace volume to avoid root-owned /usr/local. On macOS Homebrew, ensure the brew user owns /usr/local or /opt/homebrew; permission drift there is common after OS upgrades. Avoid mixing sudo and user installs because it creates root-owned artifacts that keep failing future installs. Windows/WSL users should watch for Defender/EDR locks and enable Developer Mode to allow npm-created symlinks and temp files.
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm