How to fix npm ERR! code ENOENT npm ERR! ENOENT: no such file or directory, open '/home/user/.npm/_cacache' in npm
The _cacache directory, which npm uses to store downloaded packages and metadata, is missing or inaccessible. This error occurs when npm cannot find or write to its internal cache directory.
Quick fix
Fixes npm ERR! code ENOENT npm ERR! ENOENT: no such file or directory, open '/home/user/.npm/_cacache'
npm config get cache- Check npm cache location
- Clear and rebuild the npm cache
- Fix permission issues (macOS/Linux)
- Verify npm installation
npm config get cachenpm ERR! code ENOENTnpm ERR! ENOENT: no such file or directory, open '/home/user/.npm/_cacache'
What this error means
The _cacache directory, which npm uses to store downloaded packages and metadata, is missing or inaccessible. This error occurs when npm cannot find or write to its internal cache directory. The _cacache folder is a content-addressable cache (using the cacache library) that stores all HTTP request data and package information. When npm cannot locate this directory or lacks permissions to access it, package installation fails with an ENOENT (Error NO ENTry) error. ENOENT specifically indicates npm can't access expected files within _cacache, typically due to: 1. The directory missing entirely 2. Permission restrictions preventing access 3. Incomplete cleanup from a previous npm operation
Typical symptoms
- npm install fails with 'ENOENT: no such file or directory ~/.npm/_cacache'
- npm ERR! code ENOENT appears in terminal output
- Package installation hangs or times out during dependency resolution
- Error message includes path to _cacache directory
- npm functions normally but certain packages fail to cache
Common causes
- Cache directory was deleted or corrupted but npm expects it to exist
- Permission denied - files in ~/.npm are owned by root (from using sudo npm)
- npm was installed globally with sudo but run locally without sudo
- Incomplete npm upgrade left cache in inconsistent state
- Antivirus or security software deleted cache files as suspicious
- File system issue or disk space exhaustion caused cache corruption
How to fix "npm ERR! code ENOENT npm ERR! ENOENT: no such file or directory, open '/home/user/.npm/_cacache'"
First, verify where npm expects the cache to be:
npm config get cacheOn Windows, this typically shows %LocalAppData%\npm-cache.
On macOS/Linux, this shows ~/.npm.
Run the cache clean command with the force flag:
npm cache clean --forceThis deletes the entire cache directory and removes corrupted files. npm will automatically recreate the _cacache directory on the next install.
If you previously used sudo npm install, the ~/.npm directory may be owned by root:
sudo chown -R $(whoami) ~/.npmThis ensures your user account owns the cache directory.
Verify the cache is functioning properly:
npm cache verifyThis garbage collects unneeded data and verifies the integrity of the cache index. It will confirm that _cacache and related directories are present and accessible.
If the issue persists, perform a complete clean install:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installThis removes all cached packages and local dependencies, forcing npm to rebuild everything from scratch.
If you continue experiencing permission issues, configure npm to use a different cache directory:
npm config set cache ~/.npm-globalVerify the configuration:
npm config get cacheThis avoids permission conflicts with system directories.
Advanced notes
Cache locations by OS:
- macOS/Linux: ~/.npm/_cacache
- Windows: %LocalAppData%\npm-cache\_cacache
Avoid sudo npm: Using sudo npm install creates root-owned files in ~/.npm that your user account cannot modify later. Use a Node version manager like nvm to install Node.js without requiring sudo.
Self-healing cache: npm v5+ cache is designed to recover automatically from minor corruption. Use npm cache verify instead of npm cache clean when possible.
Antivirus interference: On some systems (particularly Windows), security software may delete cache files. Whitelist your npm cache directory if you see repeated failures.
Frequently asked questions
- What does "npm ERR! code ENOENT npm ERR! ENOENT: no such file or directory, open" mean?
- The _cacache directory, which npm uses to store downloaded packages and metadata, is missing or inaccessible. This error occurs when npm cannot find or write to its internal cache directory. The _cacache folder is a content-addressable cache (using the cacache library) that stores all HTTP request data and package information.
- How do I fix "npm ERR! code ENOENT npm ERR! ENOENT: no such file or directory, open"?
- The _cacache directory, which npm uses to store downloaded packages and metadata, is missing or inaccessible. This error occurs when npm cannot find or write to its internal cache directory.
- What causes "npm ERR! code ENOENT npm ERR! ENOENT: no such file or directory, open"?
- Cache directory was deleted or corrupted but npm expects it to exist Permission denied - files in ~/.npm are owned by root (from using sudo npm) npm was installed globally with sudo but run locally without sudo
- Is the "npm ERR! code ENOENT npm ERR! ENOENT: no such file or directory, open" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐npm docs: cache command(Official Docs)
- ๐npm GitHub Issues(GitHub)
- ๐ฌSO: npm ENOENT(Stack Overflow)