How to fix npm ERR! Error: EACCES: permission denied, unlink '/usr/local/lib/node_modules/.<package>.DELETE' in npm
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- Force-delete stale temp folders
- Switch to a user-owned prefix or nvm/fnm
- Realign ownership if you own the machine
- Whitelist node_modules in AV/Defender
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging \$(npm config get prefix)/lib/node_modules/.*.DELETE 2>/dev/null || truenpm 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
- 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
- Editors or shells keeping file handles inside global node_modules
- 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'"
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging \
$(npm config get prefix)/lib/node_modules/.*.DELETE 2>/dev/null || truemkdir -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 $HOMEsudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}Add your global prefix to AV exclusions so unlink/rename is not blocked. Close VS Code or terminals that keep handles open.
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
- 📚npm Official Documentation
- 📖npm Docs: Resolving EACCES globally(Official Docs)
- 💬Stack Overflow: EPERM/EACCES on unlink during npm install(Stack Overflow)
- 🐙