How to fix npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node_modules/.<package>.DELETE' in npm

npmBEGINNERMEDIUMUpdated Dec 2, 2025· 240 views

npm cannot remove its temp .DELETE/.staging folders because they are root-owned or locked. Clean them, move to a user-writable prefix, and prevent AV or other processes from holding the files.

Quick fix

Fixes npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node_modules/.<package>.DELETE'

sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging \
  $(npm config get prefix)/lib/node_modules/.*.DELETE 2>/dev/null || true
  1. Force-delete stale temp folders
  2. Switch to a user-owned prefix or nvm/fnm
  3. Realign ownership if you own the machine
  4. Whitelist node_modules in AV/Defender
npm — error
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging \
$(npm config get prefix)/lib/node_modules/.*.DELETE 2>/dev/null || true
npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node_modules/.<package>.DELETE'

What this error means

npm stages global installs in temporary .staging folders and cleans them with unlink/rename. If those folders are owned by root (from earlier sudo installs) or locked by AV/EDR, npm's unlink fails and the install aborts, leaving partially staged content. The problem is common on Windows/WSL when Defender scans node_modules, and on macOS/Linux when mixing sudo and non-sudo installs leaves root-owned temp artifacts under the global prefix.

Typical symptoms

  • npm install -g fails unlinking .DELETE or .staging under the global prefix
  • Staging/temp folders require sudo/Admin to remove
  • Subsequent installs keep failing until temp folders are cleaned
  • AV/Defender alerts or file-in-use messages around node_modules
  • Non-root CI/WSL runs fail while sudo/Admin works

Common causes

  1. Root-owned .staging/.DELETE directories from prior sudo npm installs
  2. Global prefix still owned by root/system packages
  3. Windows Defender or corporate EDR holding locks on staging files
  4. Editors or shells keeping file handles inside global node_modules
  5. Docker/CI running npm as non-owner of the mounted prefix

How to fix "npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node_modules/.<package>.DELETE'"

1Force-delete stale temp folders
bash
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging \
  $(npm config get prefix)/lib/node_modules/.*.DELETE 2>/dev/null || true
2Switch to a user-owned prefix or nvm/fnm
bash
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"
# or install Node with nvm to keep globals in $HOME
3Realign ownership if you own the machine
bash
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
4Whitelist node_modules in AV/Defender

Add your global prefix to AV exclusions so unlink/rename is not blocked. Close VS Code or terminals that keep handles open.

5Clean cache and reinstall
bash
npm cache clean --force
npm install -g <package>

Advanced notes

In Docker/CI, ensure npm runs as the filesystem owner or set prefix to a workspace path owned by the job user; root-owned layers will block unlink. Windows/WSL users often hit EPERM/EACCES from Defender scans—Developer Mode plus AV exclusions reduce locks on temp files. Avoid mixing sudo and user installs; it consistently leaves root-owned staging folders that require manual cleanup.

Frequently asked questions

What does "npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node" mean?
staging folders and cleans them with unlink/rename. If those folders are owned by root (from earlier sudo installs) or locked by AV/EDR, npm's unlink fails and the install aborts, leaving partially staged content. The problem is common on Windows/WSL when Defender scans node_modules, and on macOS/Linux when mixing sudo and non-sudo installs leaves root-owned temp artifacts under the global prefix.
How do I fix "npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node"?
npm cannot remove its temp .DELETE/.staging folders because they are root-owned or locked. Clean them, move to a user-writable prefix, and prevent AV or other processes from holding the files.
What causes "npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node"?
Root-owned .staging/.DELETE directories from prior sudo npm installs Global prefix still owned by root/system packages Windows Defender or corporate EDR holding locks on staging files
Is the "npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading