How to fix npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>' in npm

npmBEGINNERMEDIUMUpdated Dec 2, 2025· 283 views

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
  1. Clean node_modules and temp folders
  2. Fix ownership for workspace and prefix
  3. Use user-owned cache and prefix
  4. Release Windows/WSL locks
npm — error
rm -rf node_modules package-lock.json
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || true
npm 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

  1. Destination folder owned by root/system (global prefix or node_modules)
  2. Stale .staging directories from earlier sudo installs
  3. Windows Defender/AV or VS Code holding file handles, blocking rename
  4. WSL2/NTFS mounts with restrictive ACLs or long-path limitations
  5. Docker/CI running npm as a non-owner of the workspace volume
  6. Filesystem read-only or nearly full, preventing rename/replace

How to fix "npm ERR! Error: EACCES: permission denied, rename '<from>' -> '<to>'"

1Clean node_modules and temp folders
bash
rm -rf node_modules package-lock.json
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || true
2Fix ownership for workspace and prefix
bash
sudo chown -R $(whoami) .
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
3Use user-owned cache and prefix
bash
npm config set cache ~/.npm-cache
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"
4Release Windows/WSL locks

Close VS Code/terminals, add Defender exclusions for the project and npm cache, and enable Developer Mode to reduce symlink/rename restrictions.

5Retry with a clean, reproducible install
bash
npm cache clean --force
npm ci

ci recreates node_modules from scratch, avoiding partial folders.

6Match permissions in Docker/CI

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