AI Diagnostic Summary

npm ERR! code EACCES

Well-Documented Error

This error matches known, documented patterns with reliable solutions.

Quick Fix (Most Common Solution)

Seeing "npm ERR! code EACCES"? This error can be frustrating, but it's usually fixable. It typically affects your development workflow or system. Below you'll find clear, step-by-step solutions to resolve this issue.

High confidence
What This Error Means

npm lacks permission to write to the global node_modules directory.

Frequently documented in developer and vendor support forums.

Based on documented solutions and common real-world fixes.
Not affiliated with browser, OS, or device manufacturers.

New here? Learn why exact error messages matter →

Common Causes
  • Installing global packages without sudo
  • Incorrect npm directory ownership
  • Restricted file system permissions
How to Fix
  1. Use nvm to manage Node versions
  2. Change npm default directory ownership
  3. Use sudo npm install -g (not recommended)

Last reviewed: April 2026 How we review solutions

Version note: Most common on Linux systems with Node installed via package manager (apt, yum). Not typically seen with nvm-managed installs.

Environment-Specific Commands

Linux

  1. mkdir -p ~/.npm-global
  2. npm config set prefix '~/.npm-global'
  3. Add export PATH=~/.npm-global/bin:$PATH to ~/.bashrc
  4. source ~/.bashrc

macOS

  1. Install nvm: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  2. nvm install --lts
  3. nvm use --lts
  4. Global installs now work without sudo

Windows

  1. Run terminal as Administrator, or
  2. Use nvm-windows: download from github.com/coreybutler/nvm-windows
  3. nvm install lts
  4. nvm use lts
Quick Diagnostic Path
  • If Error path contains /usr/lib/node_modules Change npm prefix: npm config set prefix ~/.npm-global
  • If Error path contains ~/.npm or ~/.config Fix ownership: sudo chown -R $(whoami) ~/.npm ~/.config
  • If Error occurs only in CI/CD Run npm ci --ignore-scripts or add --unsafe-perm flag
If This Still Fails, Check
  • After fixing permissions, old global packages may still reference the old directory — reinstall them
  • Docker containers running as root: set --unsafe-perm or use a non-root user with correct ownership
  • WSL2 users: Windows-mounted drives (/mnt/c/) have fixed permissions — work inside the Linux filesystem instead
Checking and fixing npm directory ownership
# Check current prefix
npm config get prefix

# If /usr/local, change to user-owned directory
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

# Verify
npm install -g npm  # Should work without sudo

OS-Specific Behavior

EACCES Manifests Differently on Linux, macOS, and Windows

On Linux servers — especially when Node.js was installed via apt, yum, or dnf — the global node_modules directory is typically owned by root, requiring sudo for global installs. This creates a compounding problem: future installs and npm scripts create root-owned files, making subsequent user-level installs fail with EACCES again. On macOS, the issue splits across installation methods. Homebrew on Intel Macs placed globals in /usr/local, which was user-writable. On Apple Silicon Macs, Homebrew installs to /opt/homebrew, which requires the user to be in the staff group with correct ownership. Using nvm on any macOS version sidesteps all of this. Windows presents a different pattern: EACCES rarely occurs on Windows because Windows uses a different error code (EPERM) for permission denials. When you see EACCES on Windows, you are likely running inside WSL (Windows Subsystem for Linux) and the npm directory is on a Windows-mounted filesystem (/mnt/c/), which does not support Unix permission bits. Moving your project to the Linux native filesystem (~/) resolves it immediately without any permission changes.

Optional follow-up

Some users ask whether saving fixes for recurring errors would be useful when the same issue appears again.

Was this explanation helpful?

Explanations are based on documented fixes, real-world reports, and common system behavior. GetErrorHelp is independent and not affiliated with software vendors, device manufacturers, or service providers.
Frequently Asked Questions

Why does npm need sudo?

Global installs write to system directories that require elevated permissions by default.

Is using sudo with npm safe?

It can cause permission issues. Using nvm or fixing directory ownership is preferred.

Related Resources

Also Known As

Common Search Variations

Related Errors
Still Stuck?

Paste a different error message or upload a screenshot to get help instantly.

Solutions are based on commonly documented fixes and may not apply in all situations.