node_modules Ate My Mac: Cleaning JS & Package Manager Caches
The joke writes itself — the heaviest object in the universe, etc. — but the
disk usage is real: a single JavaScript project's node_modules
easily weighs 300 MB–1 GB, and most of us have dozens of cloned
repos. Add the caches that npm, Yarn, pnpm, CocoaPods, Homebrew and Gradle
keep on the side, and a developer Mac routinely hides 20–50 GB of
perfectly rebuildable files.
Step 1: Find every node_modules on your disk
find ~ -name "node_modules" -type d -prune 2>/dev/null | xargs du -sh | sort -rh | head -20
This lists your twenty heaviest node_modules folders, biggest
first. The -prune flag stops find from descending
into them (they contain hundreds of thousands of files — without it
the command takes forever).
Delete the ones belonging to projects you're not actively working on. It's
completely safe: npm install (or yarn/pnpm) restores everything
from the lockfile whenever you return to the project.
Step 2: Clear the package manager caches
Each package manager also keeps a global cache of every tarball it ever downloaded:
# npm (cache lives in ~/.npm)
npm cache clean --force
# Yarn
yarn cache clean
# pnpm — removes packages no project references anymore
pnpm store prune
# CocoaPods (~/Library/Caches/CocoaPods)
pod cache clean --all
# Homebrew — old versions and downloads
brew cleanup --prune=all
# Gradle caches (Android / KMP projects)
rm -rf ~/.gradle/caches
These caches exist to make installs faster and offline-friendly. Clearing them costs you nothing but a slower next install — every package is re-downloaded on demand.
Step 3: Don't forget the long tail
- Docker:
docker system prunereclaims images and build cache — often 10 GB+ on its own. - Old virtualenvs / .venv folders in abandoned Python projects.
- Rust:
~/.cargo/registryand per-projecttarget/folders grow fast;cargo cleanper project.
The real problem: they all grow back
Every folder in this article regenerates by design. Clean once and in three
months you're back where you started. The sustainable fix is visibility —
knowing which projects and caches got heavy again, without manually
running du across your home directory.
One scan finds them all
Dev Box Cleaner scans your disk and its Smart Cleanup groups
every node_modules, npm/Yarn/pnpm/CocoaPods/Homebrew/Gradle
cache and Xcode leftover into tidy categories with running totals — tick and
clean in one go, safely via the Trash. The treemap shows exactly which
projects got fat, and rescans take seconds thanks to incremental scanning.