· · 7 min read

How to Clean Developer Tool Caches on Mac: npm, Homebrew, Docker & More

If you develop on a Mac, your disk is silently filling up with cached packages, old build artifacts, and orphaned images. Here is exactly where they live, how big they get, and the single command to eliminate each one — plus how TrimyMac automates the entire process.

For Xcode-specific storage, use the focused guides to remove old Simulator runtimes and review Xcode archives without losing important dSYMs.


In this article
  1. npm cache and node_modules
  2. Homebrew cache
  3. pip cache
  4. Cargo cache
  5. Docker images, volumes & build cache
  6. CocoaPods cache
  7. FAQ

Open a Terminal and run du -sh ~/Library/Caches ~/.npm ~/.cargo/registry ~/.cocoapods on any active development Mac and the numbers are sobering. Between npm's global package cache, Homebrew's downloaded bottles, Docker's dangling images, and all the other runtime caches that accumulate over months of work, it is completely normal to find 20–50 GB sitting in directories you have never thought about. The good news: almost all of it is safe to delete and will be regenerated on demand.

This guide covers every major developer tool cache on macOS with the exact file paths, realistic size ranges, the terminal command to clear it, and whether TrimyMac's Smart Clean module handles it automatically. Follow along for each tool you use, or scroll to the FAQ for quick answers.

📦

1. npm Cache & node_modules

Path: ~/.npm
Typical size: 1–8 GB
TrimyMac: Automated

npm maintains a persistent content-addressable cache at ~/.npm so that packages you have already downloaded do not need to be fetched again on future npm install runs. This is genuinely useful behavior, but it has no built-in expiry. On a machine that has been active for a year or more, ~/.npm routinely grows to 3–8 GB, filled with tarballs for every version of every package you have ever installed. The cache is safe to wipe at any time — npm will re-download what it needs on the next install.

Separate from the global npm cache, each project's node_modules folder is another major culprit. A typical React or Next.js project's node_modules is 300–700 MB. If you have ten projects checked out, that is potentially 5+ GB in dependency trees that can be fully restored with a single npm install. These folders do not live in a single location, so the first step is finding them.

Find all node_modules folders and their sizes
find ~ -name "node_modules" -type d -prune 2>/dev/null \
  | xargs du -sh 2>/dev/null | sort -hr
Clear the global npm cache
npm cache clean --force
Delete a project's node_modules (run from project root)
rm -rf node_modules
# Restore later with:
npm install
✓

TrimyMac automates this. Smart Clean detects both ~/.npm and stale node_modules folders across your home directory, shows the total size, and lets you remove them in one click. It flags folders that have not been accessed in 30+ days as safe candidates so you do not accidentally delete an active project's dependencies.

🍺

2. Homebrew Cache

Path: ~/Library/Caches/Homebrew
Typical size: 1–5 GB
TrimyMac: Automated

Every time Homebrew downloads a package bottle — pre-compiled binaries for formulae like git, ffmpeg, postgresql, or node — it saves a copy to ~/Library/Caches/Homebrew. Older versions are never automatically removed, so this folder accumulates stale bottles for every formula version you have ever installed or upgraded. By default Homebrew also keeps old versions of installed formulae in its Cellar, each one taking tens to hundreds of megabytes.

Running brew cleanup removes stale downloads and old formula versions under Homebrew's current rules. You can preview what would be deleted with the --dry-run flag before committing. For command scope, retention choices, and a GUI alternative, use the focused Homebrew cache cleanup guide.

Preview what will be removed (dry run)
brew cleanup --dry-run
Remove stale downloads and old formula versions
brew cleanup
# Also clean older cached downloads (>120 days):
brew cleanup --prune=all
ℹ️

The Homebrew cache directory on Apple Silicon Macs is at /opt/homebrew/var/homebrew/logs for logs and ~/Library/Caches/Homebrew for downloaded archives. If you installed Homebrew in a custom prefix, check brew --cache to get the actual path on your machine.

✓

TrimyMac automates this. The Smart Clean "Homebrew" category runs brew cleanup --prune=all under the hood and reports how much was recovered, without you needing to open a terminal.

🐍

3. pip Cache

Path: ~/.cache/pip  or  ~/Library/Caches/pip
Typical size: 500 MB–3 GB
TrimyMac: Automated

pip, the Python package installer, stores downloaded wheel files and source distributions in a local cache so that re-installing the same package version does not require an internet round-trip. On macOS the cache lives at ~/Library/Caches/pip (for pip installed via Homebrew or pyenv with a standard macOS configuration) or at ~/.cache/pip on systems that follow the XDG convention.

If you regularly install packages into virtual environments, work with data science stacks like TensorFlow or PyTorch, or frequently switch Python versions, the pip cache fills up rapidly with large wheel files for packages you may no longer use. The command pip cache purge (available from pip 20.1+) wipes the entire cache cleanly.

See how much pip has cached
pip cache info
# Shows cache location and total size
Remove all cached pip packages
pip cache purge
Or manually remove the cache directory
# macOS (Homebrew Python / pyenv)
rm -rf ~/Library/Caches/pip

# XDG-style location (some setups)
rm -rf ~/.cache/pip
⚠️

Virtual environment folders (venv/, .venv/) inside your project directories are a separate concern. They are not the pip cache, but they duplicate installed packages and can be multi-hundred-MB each. Delete a virtual environment and recreate it with python -m venv .venv && pip install -r requirements.txt.

✓

TrimyMac automates this. Smart Clean checks both ~/Library/Caches/pip and ~/.cache/pip and presents the combined size for removal in one step.

🦀

4. Cargo Cache

Path: ~/.cargo/registry
Typical size: 2–15 GB
TrimyMac: Automated

Rust developers often have the largest package caches of any ecosystem. Cargo, Rust's package manager, maintains a local registry at ~/.cargo/registry that contains downloaded source archives (src/) and compiled index data (cache/) for every crate version ever fetched. Additionally, Cargo keeps compiled artifacts in the target/ directory inside each project — these can grow to gigabytes per project for large dependency trees.

The recommended tool for managing Cargo's cache intelligently is cargo-cache, a plugin that shows a detailed breakdown and provides a targeted --autoclean option that removes only the source code for crate versions with no installed binary, keeping the build cache for your currently active crates intact.

Install cargo-cache (one time)
cargo install cargo-cache
See a breakdown of Cargo's disk usage
cargo cache
Remove stale source cache entries automatically
cargo cache --autoclean
Nuclear option — wipe the entire registry (safe, slow to rebuild)
rm -rf ~/.cargo/registry

For project-level target/ directories, the quickest cleanup is cargo clean from the project root, or you can find them all and remove manually:

Find all Rust target/ directories
find ~ -name "target" -path "*/rust/*" -prune -type d 2>/dev/null \
  | xargs du -sh 2>/dev/null | sort -hr
✓

TrimyMac automates this. TrimyMac scans ~/.cargo/registry and surfaces stale cached crate source archives alongside your project target/ directories, grouping them for easy bulk removal.

🐳

5. Docker: Images, Volumes & Build Cache

Path: Docker.raw (VM disk image)
Typical size: 5–40 GB
TrimyMac: Guided

Docker on Mac stores everything inside a virtual machine disk image, typically located at ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw on Docker Desktop. This file grows aggressively as you pull new images, run containers that write data to volumes, and perform builds that layer new intermediate images. Critically, this file does not automatically shrink when you delete images — the VM disk file reclaims space lazily, or in some versions not at all without a manual reset.

Docker's storage breaks down into four main categories you should clean independently:

  • Images — pulled base images and locally built images, including dangling layers from intermediate builds
  • Containers — stopped containers still occupy their writable layer on disk
  • Volumes — named and anonymous data volumes that persist after containers stop
  • Build cache — layers cached by BuildKit to speed up repeated builds, often the largest and most overlooked category
See Docker's actual disk usage breakdown
docker system df
# Shows images, containers, volumes, build cache sizes
Remove everything not actively used (recommended approach)
docker system prune
# Removes: stopped containers, dangling images, unused networks, build cache
# Add --volumes to also remove unused named volumes (careful!)
docker system prune --volumes
Remove only dangling images (no containers)
docker image prune
Remove all unused images (not just dangling)
docker image prune -a
Remove only the build cache
docker builder prune
# Add -a to remove all cache, not just dangling layers
docker builder prune -a
⚠️

The --volumes flag on docker system prune will permanently delete named volumes, including any databases or persistent data stored in containers. Double-check your volume contents with docker volume ls before including this flag.

Even after running prune commands, Docker Desktop's virtual disk file may not shrink immediately because the file system inside the VM still reports the old allocated size. In Docker Desktop, go to Settings → Resources → Disk image location to see the current disk image size. If it is still bloated, clicking "Clean / Purge data" forces a full reclaim.

ℹ️

TrimyMac guided cleanup. Because Docker data lives inside a VM disk image rather than normal macOS files, TrimyMac detects the Docker.raw size and guides you to the exact Docker Desktop controls and prune commands to recover that space, rather than operating on the raw VM file directly.

💻

6. CocoaPods Cache

Path: ~/.cocoapods
Typical size: 500 MB–4 GB
TrimyMac: Automated

CocoaPods, the dependency manager used in iOS and macOS development, stores two things in ~/.cocoapods: the full specs repository (a git repo of every public pod specification, sitting at ~/.cocoapods/repos) and downloaded pod source archives. The specs repo alone can be 400–700 MB, and it never automatically prunes old data. If you have worked across multiple iOS projects or upgraded many pods over the years, the total can easily exceed 2 GB.

There is no single built-in command equivalent to brew cleanup for CocoaPods, but the cache has two parts you can target separately. The specs repo can be updated to remove stale spec entries, and the downloaded pod cache can be cleared entirely.

See your CocoaPods cache size
du -sh ~/.cocoapods
Clear the entire CocoaPods cache
pod cache clean --all
# Removes all locally cached pod source zips
Remove the specs repo (will be re-cloned on next pod install)
rm -rf ~/.cocoapods/repos
# Then update to pull a fresh copy:
pod repo update
Full nuclear reset (removes all of ~/.cocoapods)
rm -rf ~/.cocoapods
# Re-setup with:
pod setup

If you are on a project using CocoaPods, the Pods/ directory in your project root is also regenerated by pod install and can be safely deleted when not actively developing. Add Pods/ to .gitignore in new projects to avoid committing it entirely.

✓

TrimyMac automates this. TrimyMac's Smart Clean identifies ~/.cocoapods and project-level Pods/ directories, shows you the size of each component (specs repo vs. downloaded pods), and lets you selectively or fully remove them without running multiple terminal commands.

How Much Space Can You Actually Recover?

On a Mac that has been in active development for 12–24 months without any manual cleanup, the numbers stack up fast. Here is a realistic example of what you might find:

That is over 32 GB — from just these six tool categories, before accounting for Xcode's DerivedData folder (routinely 10–30 GB on its own), iOS device backups, or general application caches. These are not edge cases. They represent normal developer machine hygiene debt that builds up quietly in the background.

The good news is that every gigabyte above is fully regenerated on demand. None of these caches contain original work or irreplaceable data. You are deleting redundant copies of things that can be fetched, compiled, or computed again.

Let TrimyMac find this waste automatically

Instead of hunting each directory manually, TrimyMac scans all six tool caches in seconds, shows you the exact sizes, and cleans them in one click — no terminal required.

Building a Maintenance Habit

Running these commands once is satisfying but not a long-term strategy. Developer tool caches regenerate within days of active work. The practical approach is to either run a monthly cleanup pass or automate it.

For manual monthly cleanup, a simple shell script chains the most impactful commands:

One-shot developer cache cleanup script
#!/bin/zsh
# Run monthly: chmod +x cleanup.sh && ./cleanup.sh

echo "Cleaning npm cache..."
npm cache clean --force

echo "Cleaning Homebrew..."
brew cleanup --prune=all

echo "Cleaning pip cache..."
pip cache purge

echo "Cleaning Cargo cache..."
cargo cache --autoclean

echo "Cleaning Docker..."
docker system prune -f
docker builder prune -f

echo "Cleaning CocoaPods..."
pod cache clean --all

echo "Done. Check disk space:"
df -h /

Alternatively, TrimyMac Pro's scheduled auto-clean feature handles all of this silently on a schedule you define — daily, weekly, or monthly — without any terminal or manual steps. You set it once and forget it.

Frequently Asked Questions

Quick answers to the most common questions about cleaning developer caches on Mac.

How do I clear npm cache on Mac?

Run npm cache clean --force in Terminal. This removes all downloaded package tarballs from ~/.npm. The cache will be rebuilt as needed the next time you run npm install in any project. You can check the current size first with du -sh ~/.npm — on active machines this is typically 1–8 GB.

Why is Docker taking so much space on my Mac?

Docker on Mac stores all images, containers, volumes, and build cache inside a virtual machine disk image file (Docker.raw). This file grows whenever you pull images or run builds, but does not automatically shrink when you delete images — the VM file system allocates space pessimistically. Run docker system df to see the breakdown, then docker system prune -a --volumes to remove everything unused. After pruning, open Docker Desktop → Settings → Resources to reclaim the actual disk file space. The build cache alone can be 5–15 GB on active machines.

Can I delete node_modules safely?

Yes, absolutely. The node_modules directory inside any project is entirely regenerated by running npm install (or yarn install / pnpm install). It contains no original code — only installed copies of packages listed in package.json and package-lock.json. Always make sure you have a valid package-lock.json or yarn.lock committed to version control before deleting, so the exact dependency tree can be reproduced. Deleting node_modules in projects you are not actively working on is one of the easiest ways to reclaim 5–10 GB on a typical development Mac.

How do I free space from developer tools on Mac?

The most impactful steps in order: (1) Clean Docker with docker system prune -a — this alone often recovers 10+ GB. (2) Delete stale node_modules folders from old JavaScript projects. (3) Run brew cleanup --prune=all to remove old Homebrew bottles. (4) Clear the Cargo registry with cargo cache --autoclean if you write Rust. (5) Run npm cache clean --force and pip cache purge to clear package download caches. (6) Clean CocoaPods with pod cache clean --all if you develop for iOS/macOS. If you also use Xcode, clearing DerivedData can recover another 10–30 GB.

How do I clean Homebrew cache on Mac?

Run brew cleanup to remove old formula versions and cached downloads for uninstalled packages. For a more aggressive cleanup, use brew cleanup --prune=all which removes all cached downloads regardless of age. You can preview what will be deleted without actually removing anything by adding --dry-run. The cache lives at ~/Library/Caches/Homebrew — you can check its current size with du -sh ~/Library/Caches/Homebrew. Running brew cleanup monthly is generally enough to keep this under control.

Will clearing these caches break anything?

No. Every cache covered in this article stores downloaded or compiled copies of data that can be regenerated. Clearing them means the next install or build will take longer because it has to re-download or recompile, but nothing will break permanently. Your source code, project files, installed applications, and system files are never touched. The only exception to be careful about is Docker volumes with the --volumes flag — if a running service stores its database in a Docker volume, deleting that volume deletes the data. Always check with docker volume ls before pruning volumes.

How often should I clean developer tool caches on Mac?

For most developers, a monthly cleanup is sufficient. If you are actively switching between many projects, pulling new Docker images frequently, or doing heavy data science work with pip, you may want to run cleanup every two weeks. Signs that it is overdue: your Mac's available storage drops below 20 GB, Spotlight indexing slows down, or you notice build times degrading. TrimyMac Pro's scheduled auto-clean can handle this automatically on whatever cadence works for you.