How to fix npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>' in npm
npm cannot rename a temp folder or package because the destination is not writable or the source is locked. Release locks, fix ownership, and use user-owned prefixes before retrying.
Quick fix
Fixes npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>'
rm -rf node_modules package-lock.json
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || true- Clean node_modules and temp folders
- Fix ownership for workspace and prefix
- Use user-owned cache and prefix
- Release Windows/WSL locks
rm -rf node_modules package-lock.jsonsudo rm -rf $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || truenpm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>'
What this error means
npm renames .staging directories into final package folders during install. If the destination is root-owned, read-only, or held open by another process, the rename syscall fails with EACCES and npm aborts. This shows up after mixing sudo and non-sudo installs, on WSL2 with NTFS ACLs, inside Docker/CI when the workspace is root-owned, and on Windows when VS Code/Defender or long-path policy blocks the rename.
Typical symptoms
- npm install/ci fails with EACCES or EPERM on rename of .staging to node_modules/<pkg>
- Install works with sudo/Admin but not as normal user
- Windows/WSL shows file-in-use or Defender alerts during install
- Repeated failures on the same package until node_modules is cleaned
- CI/Docker jobs fail on rename while local installs succeed
Common causes
- Destination folder owned by root/system (global prefix or node_modules)
- Stale .staging directories from earlier sudo installs
- Windows Defender/AV or VS Code holding file handles, blocking rename
- WSL2/NTFS mounts with restrictive ACLs or long-path limitations
- Docker/CI running npm as a non-owner of the workspace volume
- Filesystem read-only or nearly full, preventing rename/replace
How to fix "npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>'"
rm -rf node_modules package-lock.json
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || truesudo chown -R $(whoami) .
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}npm config set cache ~/.npm-cache
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"Close VS Code/terminals, add Defender exclusions for the project and npm cache, and enable Developer Mode to reduce symlink/rename restrictions.
npm cache clean --force
npm cici recreates node_modules from scratch, avoiding partial folders.
Use docker run --user to match host UID/GID or chown the bind-mounted workspace before npm install so rename can replace directories.
Advanced notes
On WSL2, working inside /mnt/c uses NTFS ACLs that can block renames; move the repo to the Linux filesystem for consistent POSIX permissions. Long Windows paths can also break renames—keep the project path short. In Docker, bind mounts inherit host ownership; matching UID or chowning the volume prevents EACCES during rename. Avoid mixing sudo and user installs; root-owned .staging directories repeatedly block replacement.
Frequently asked questions
- What does "npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>'" mean?
- staging directories into final package folders during install. If the destination is root-owned, read-only, or held open by another process, the rename syscall fails with EACCES and npm aborts. This shows up after mixing sudo and non-sudo installs, on WSL2 with NTFS ACLs, inside Docker/CI when the workspace is root-owned, and on Windows when VS Code/Defender or long-path policy blocks the rename.
- How do I fix "npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>'"?
- npm cannot rename a temp folder or package because the destination is not writable or the source is locked. Release locks, fix ownership, and use user-owned prefixes before retrying.
- What causes "npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>'"?
- Destination folder owned by root/system (global prefix or node_modules) Stale .staging directories from earlier sudo installs Windows Defender/AV or VS Code holding file handles, blocking rename
- Is the "npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>'" 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 for npm(Official Docs)
- 📖Microsoft Docs: WSL file permission considerations(Official Docs)
- 💬Stack Overflow: npm install EPERM/EACCES rename/unlink(Stack Overflow)
- 🐙