Where Does npm Store Cache and Global Packages?
Where npm keeps its cache and global packages on each OS, and how to relocate them safely.
Last updated
npm splits runtime state two ways: a cache folder holding downloaded tarballs and metadata, plus a prefix folder holding global installs. Defaults live per OS under the paths below, overridable with npm config.
Permission errors almost always trace to a root-owned prefix from an old sudo install. Move the prefix to your home dir and add its bin to PATH. The cache itself is disposable; the prefix is the one to back up.
Where npm stores this, by platform
~/.npm/
Tarballs and metadata. Relocate with npm config set cache. Global packages live separately under the prefix (npm config get prefix), usually /usr or ~/.npm-global.
%LOCALAPPDATA%\npm-cache\
Same cache role. Global prefix defaults under Roaming AppData. Inspect with npm config get prefix; fix EACCES by moving prefix user-local.
~/.npm/
Same split as Linux. Homebrew and nvm installs pick different prefixes, so always check npm config get prefix rather than assuming.
Frequently asked questions
How do I clean the npm cache?
Run npm cache verify first; it checks integrity without deleting. For a full wipe use npm cache clean --force, then reinstall. Only clean with network available since every package re-downloads.
How do I find my live npm paths?
Run npm config get prefix and npm config get cache to print the live paths. Global bins link from the prefix folder. Set prefix to a user-owned dir to fix permission errors instead of using sudo.
Notice an outdated path? Let us know.