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.
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.
Verify where npm thinks the global directory should be:
npm config get prefix
npm config list | grep prefixNote the path returned. If this path doesn't exist, it's the root cause.
Check if the directory actually exists:
ls -la /usr/local/lib/node_modules
# or:
ls -la $(npm config get prefix)/lib/node_modulesIf you get a "No such file or directory" error, the directory needs to be created.
If the directory doesn't exist, create it with proper permissions:
mkdir -p /usr/local/lib/node_modules
mkdir -p /usr/local/binThen ensure you own these directories:
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/binInstead of fixing system directories, configure npm to use a directory in your home folder:
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'Then add to your PATH in ~/.bashrc or ~/.zshrc:
export PATH=~/.npm-global/bin:$PATHApply changes: source ~/.bashrc
Test that global installations work:
npm install -g npm
npm list -g --depth=0On 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.
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm