Guide

How to clear npm cache on Mac, and what it keeps.

npm keeps a copy of every package version it has ever downloaded, and it never deletes any of them on its own. Here's where that lives on a Mac and how to reclaim it.

The short version

Run npm cache clean --force. It empties ~/.npm/_cacache, where npm keeps every package it has downloaded. Your projects and their node_modules folders aren't touched, and npm downloads packages again as you install them. It doesn't clear the npx cache: move ~/.npm/_npx to the Trash for that.

npm cache location on Mac

On a Mac, npm's cache folder is ~/.npm, a hidden folder in your home folder. To confirm where yours is:

npm config get cache
WhatDefault locationOn one Mac
Package cache~/.npm/_cacache19 GB
Packages run with npx~/.npm/_npx4.8 GB
Debug logs~/.npm/_logsSmall

Sizes are from one developer Mac in October 2026: 23 GB in all. It's one folder per user, so every Node version you install with nvm, fnm, or Homebrew shares it. To move it, run npm config set cache /path/to/folder, or set the npm_config_cache environment variable.

What npm cache clean deletes

_cacache is a content-addressable store: the tarball and metadata for every package version npm has fetched, checked against its hash every time it's read. Clearing it is safe. Nothing in your projects depends on it; it only saves downloads.

  • What rebuilds: the next npm install downloads what it needs and puts it back in the cache.
  • What you lose: offline installs. --offline and --prefer-offline only work for packages that are cached.
  • What stays: _npx, _logs, your ~/.npmrc settings, and every node_modules folder.

npm's own documentation says the cache is self-healing: corrupted data is detected and fetched again. So clearing it rarely fixes an install error. Its real use is reclaiming disk space, which is why npm makes you add --force.

npm cache commands

npm config get cache                   # where the cache is
du -sh ~/.npm/_cacache ~/.npm/_npx     # how big it is
npm cache verify                       # check it and garbage-collect unneeded data
npm cache clean --force                # empty _cacache
  • npm cache verify is the gentle option. It checks every entry and removes data nothing points to anymore. It reclaims some space, not most.
  • npm cache clean --force deletes everything in _cacache. Without --force, npm refuses and explains why.
  • The npx cache holds whole installs of every package you've run with npx, one folder per package. Quit anything running through npx, then move ~/.npm/_npx to the Trash. npx downloads a package again the next time you run it.

How big the npm cache gets

npm never deletes cached data on its own, so the cache only grows. Every new version of every dependency, across every project, adds to it. A few gigabytes is normal after a year; on the developer Mac above, it reached 19 GB, plus 4.8 GB of npx installs. If you've never cleared it, it's likely one of the biggest folders in your home folder.

node_modules: usually the bigger folder

The cache is one folder. node_modules is one per project, and a single Next.js app can have hundreds of megabytes in it. To list them by size:

find ~ -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null | sort -h | tail -20

Delete the ones in projects you haven't worked on in a while. npm install brings them back from the lockfile, and npm ci deletes and reinstalls them from scratch. If you use pnpm, its shared store at ~/Library/pnpm/store is the equivalent of the npm cache: pnpm store prune removes packages no project uses. On the same Mac, it held 12 GB.

Using Yarn instead? See how to clear Yarn cache. All the others: clear cache by tool.

Disk Forecast finds this for you

Disk Forecast lists ~/.npm/_cacache and ~/.npm/_npx as separate entries under Cleanup › Safe to clear › Package manager caches, next to the pnpm store and Bun's cache. Your node_modules folders show up too, only where a package.json sits beside them: under Build folders in old projects if the project hasn't changed in 30 days, or Build folders in active projects if it has. Everything goes to the Trash. It's free.

Questions

How do I clear the npm cache?

Run npm cache clean --force. It empties ~/.npm/_cacache, and npm downloads packages again as you install them. npm requires --force because its cache is self-healing and rarely needs clearing for any reason other than disk space.

Where is the npm cache located on a Mac?

In ~/.npm, a hidden folder in your home folder. The package cache is ~/.npm/_cacache and npx installs are in ~/.npm/_npx. Run npm config get cache to confirm the location on your Mac.

Is it safe to delete the npm cache?

Yes. It's only a store of downloaded packages; no project depends on it. The next npm install downloads what it needs, so it takes longer once and offline installs stop working until the cache refills.

Does npm cache clean delete node_modules?

No. It only empties ~/.npm/_cacache. Each project's node_modules folder stays until you delete it yourself. They're often bigger in total than the cache, and npm install brings them back.

Why is my npm cache so big?

npm never deletes cached data on its own. Every version of every package you've installed, across every project and Node version, stays in it. npx adds a full install for each package you run in ~/.npm/_npx.

Know before it's full.

Free. No account, no subscription.

macOS 14 or later · Apple Silicon and Intel · brew install --cask coreyhaines31/tap/diskforecast