How to fix npm ERR! code ENOACCESS npm ERR! No access to this resource in npm

npmBEGINNERMEDIUMUpdated Dec 6, 2025· 152 views

The EACCES permission denied error occurs when npm lacks write access to global package directories. Fix it by using nvm to manage Node.js, changing npm's default directory, or fixing directory ownership. Never use sudo with npm.

Quick fix

Fixes EACCES

# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# Restart your terminal, then install Node.js
nvm install 20
nvm use 20

# Verify
node --version
npm --version
  1. Use nvm to manage Node.js (recommended)
  2. Change npm's default directory
  3. Fix existing directory ownership
  4. Fix npm cache permissions
npm — error
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Restart your terminal, then install Node.js
nvm install 20
nvm use 20
# Verify
node --version
npm --version
npm ERR! code ENOACCESS
npm ERR! No access to this resource

What this error means

This error occurs when npm cannot write to the directories it needs for installing packages—typically the global node_modules directory at /usr/local/lib/node_modules. On Unix-like systems, this directory is usually owned by root, but npm runs as your regular user. The error most commonly appears when running `npm install -g` to install global packages. npm tries to write to /usr/local but your user doesn't have write permission there. While using `sudo npm install` might seem like a quick fix, it creates files owned by root, which causes more permission problems later. The proper solution is to configure npm to use directories your user can write to.

Typical symptoms

  • Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
  • npm install -g fails with permission error
  • mkdir permission denied for node_modules directory
  • npm cache operations fail with EACCES
  • Works with sudo but fails without it
  • npm commands fail after fresh Node.js installation
  • Permission errors reference /usr/local/lib or /usr/local/bin

Common causes

  1. Global npm directories owned by root, not your user
  2. Node.js installed system-wide with root permissions
  3. Previous use of sudo npm created root-owned files
  4. Fresh Node.js installation from official installer
  5. npm cache directory has wrong ownership
  6. Multi-user system with restrictive default permissions

How to fix "npm ERR! code ENOACCESS npm ERR! No access to this resource"

1Use nvm to manage Node.js (recommended)

The best solution is to install Node.js via nvm (Node Version Manager), which avoids permission issues entirely:

bash
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# Restart your terminal, then install Node.js
nvm install 20
nvm use 20

# Verify
node --version
npm --version

nvm installs Node.js in your home directory, so no sudo is ever needed.

2Change npm's default directory

Configure npm to use a directory in your home folder:

bash
# Create directory for global packages
mkdir -p ~/.npm-global

# Configure npm to use it
npm config set prefix '~/.npm-global'

# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc

# Reload your shell
source ~/.bashrc

Now global packages install to ~/.npm-global without needing elevated permissions.

3Fix existing directory ownership

If you want to keep using /usr/local, change its ownership:

bash
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Warning: Only do this if npm's prefix is /usr/local. Never chown /usr or /usr/lib directly—that breaks your system.

First check your prefix:

bash
npm config get prefix
4Fix npm cache permissions

If the error specifically mentions the cache directory:

bash
sudo chown -R $(whoami) ~/.npm

This gives your user ownership of the npm cache, which is always in your home directory.

5Clear npm cache and retry

Sometimes corrupted cache causes permission errors:

bash
npm cache clean --force
npm install -g <package-name>
6For Windows: fix global directory

On Windows, configure npm to use a folder in your user directory:

powershell
# Create directory
mkdir "$env:USERPROFILE\.npm-global"

# Set npm prefix
npm config set prefix "$env:USERPROFILE\.npm-global"

# Add to PATH (System Properties > Environment Variables)
# Add: %USERPROFILE%\.npm-global

Restart your terminal for PATH changes to take effect.

Advanced notes

Why you should never use sudo with npm:

Running sudo npm install creates files owned by root. The next time you run npm without sudo, it can't modify those files, leading to more EACCES errors. This creates a cycle where you need sudo for everything.

Worse, npm runs arbitrary code from packages during installation. Running that code as root is a security risk—a malicious package could modify system files.

For Docker containers:

If you need npm in Docker, either:
1. Run as a non-root user: USER node after FROM node:20
2. Or use official Node.js images which handle permissions correctly

For CI/CD pipelines:

Most CI environments run as non-root users with properly configured npm. If you see EACCES in CI, check:
- Whether a previous step ran something as root
- That the workspace directory has correct permissions
- That you're not mixing sudo and non-sudo npm commands

Frequently asked questions

What does "EACCES" mean?
This error occurs when npm cannot write to the directories it needs for installing packages—typically the global node_modules directory at /usr/local/lib/node_modules. On Unix-like systems, this directory is usually owned by root, but npm runs as your regular user. The error most commonly appears when running npm install -g to install global packages.
How do I fix "EACCES"?
The EACCES permission denied error occurs when npm lacks write access to global package directories. Fix it by using nvm to manage Node.js, changing npm's default directory, or fixing directory ownership. Never use sudo with npm.
What causes "EACCES"?
Global npm directories owned by root, not your user Node.js installed system-wide with root permissions Previous use of sudo npm created root-owned files
Is the "EACCES" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading