How to fix npm ERR! code ENOENT npm ERR! Error: ENOENT, no such file or directory '/usr/local/lib/node_modules' in npm

npmINTERMEDIATEMEDIUMUpdated Dec 3, 2025· 172 views

The ENOENT error occurs when npm cannot find the global packages directory (typically /usr/local/lib/node_modules), usually because the directory doesn't exist or has permission issues. This prevents global package installations and updates from working correctly.

Quick fix

Fixes ENOENT

npm config get prefix
npm config list | grep prefix
  1. Check your current npm prefix configuration
  2. Verify the global directory exists
  3. Create missing directories (Linux/macOS)
  4. Configure npm to use a user directory
npm — error
npm config get prefix
npm config list | grep prefix
npm ERR! code ENOENT
npm ERR! Error: ENOENT, no such file or directory '/usr/local/lib/node_modules'

What this error means

ENOENT stands for 'Error: NO ENTry'. When npm tries to access the global packages directory to install or manage global packages, the system cannot find the specified path. This typically happens when the directory structure is missing, deleted, or inaccessible due to permission restrictions.

Typical symptoms

  • Global npm installations fail with 'ENOENT: no such file or directory' messages
  • Commands installed with npm install -g cannot be found or executed
  • npm update -g fails to complete
  • Error message explicitly mentions /usr/local/lib/node_modules or similar path
  • Issue started after upgrading Node.js, npm, or recent system changes

Common causes

  1. The global packages directory was deleted or never created during Node.js installation
  2. Missing permissions to access or write to /usr/local/lib/node_modules
  3. npm prefix is misconfigured and points to a non-existent directory
  4. Installation method (system package manager vs. nvm) created incompatible paths
  5. Node.js installed with sudo, creating root-owned directories that regular users cannot access

How to fix "npm ERR! code ENOENT npm ERR! Error: ENOENT, no such file or directory '/usr/local/lib/node_modules'"

1Check your current npm prefix configuration

Verify where npm thinks the global directory should be:

bash
npm config get prefix
npm config list | grep prefix

Note the path returned. If this path doesn't exist, it's the root cause.

2Verify the global directory exists

Check if the directory actually exists:

bash
ls -la /usr/local/lib/node_modules
# or:
ls -la $(npm config get prefix)/lib/node_modules

If you get a "No such file or directory" error, the directory needs to be created.

3Create missing directories (Linux/macOS)

If the directory doesn't exist, create it with proper permissions:

bash
mkdir -p /usr/local/lib/node_modules
mkdir -p /usr/local/bin

Then ensure you own these directories:

bash
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin
4Configure npm to use a user directory

Instead of fixing system directories, configure npm to use a directory in your home folder:

bash
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'

Then add to your PATH in ~/.bashrc or ~/.zshrc:

bash
export PATH=~/.npm-global/bin:$PATH

Apply changes: source ~/.bashrc

5Verify the fix

Test that global installations work:

bash
npm install -g npm
npm list -g --depth=0

Advanced notes

On systems using nvm (Node Version Manager), ensure npm's prefix is not explicitly set in ~/.npmrc. If you see 'nvm is not compatible with the npm config "prefix" option', run npm config delete prefix to remove it—nvm manages node/npm paths automatically. For Docker containers, consider using a custom prefix during installation.

Frequently asked questions

What does "ENOENT" mean?
ENOENT stands for 'Error: NO ENTry'. When npm tries to access the global packages directory to install or manage global packages, the system cannot find the specified path. This typically happens when the directory structure is missing, deleted, or inaccessible due to permission restrictions.
How do I fix "ENOENT"?
The ENOENT error occurs when npm cannot find the global packages directory (typically /usr/local/lib/node_modules), usually because the directory doesn't exist or has permission issues. This prevents global package installations and updates from working correctly.
What causes "ENOENT"?
The global packages directory was deleted or never created during Node.js installation Missing permissions to access or write to /usr/local/lib/node_modules npm prefix is misconfigured and points to a non-existent directory
Is the "ENOENT" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading