npm cannot create the global package directory because the prefix is unwritable or owned by root. Use nvm/user prefixes or fix ownership, clear staging, then reinstall.
Global installs create a package directory under prefix/lib/node_modules before copying files. If that parent directory is owned by root or mounted read-only, npm's mkdir syscall fails with EACCES and the install stops. Temporary .staging directories from past sudo installs can also remain root-owned, preventing new directories from being created. This shows up on macOS Homebrew installs, Linux servers with hardened /usr/local permissions, Docker/CI jobs running as non-root, and Windows/WSL when corporate AV interferes with mkdir inside node_modules.
npm config get prefix
ls -ld $(npm config get prefix)/lib/node_modules
sudo ls -ld $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || trueexport NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \ . "$NVM_DIR/nvm.sh"
nvm install --lts
# or
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || true
npm cache clean --forcesudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}npm install -g <package>Close editors holding node_modules, add Defender exclusions for your prefix, and retry from an elevated shell if required by policy.
On macOS with Homebrew, ensure /usr/local or /opt/homebrew remains owned by the brew user; reinstalling Node via nvm/fnm keeps globals under $HOME and avoids permission drift. In Docker/CI, set npm config prefix to a workspace-owned path or run as the image owner to avoid EACCES during mkdir. Corporate AV/EDR on Windows/WSL can lock mkdir/unlink; exclusions for node_modules and temp folders prevent recurring failures.
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