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 ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error