How to clear npm, yarn, pnpm, Cargo and Gradle caches on Mac
Every time you install a package or build a project, your tools save a local copy so the next install is faster. That's the cache. It's useful — until it quietly grows to 10, 20, or 30 GB and you're wondering why your Mac says there's no space left.
The good news: developer caches are completely safe to delete. They're downloaded copies, not source code. The only trade-off is that your next build or install will be slower — a one-time cost while the cache rebuilds itself.
Where each cache lives and how to clear it
npm
npm stores downloaded packages in ~/.npm. On a Mac that's been used for development for a year or two, this folder easily reaches 5–10 GB.
Check the size:
du -sh ~/.npm
Clear it:
npm cache clean --force
The --force flag is required since npm 5 — without it, npm will refuse. This only deletes cached tarballs and metadata; it does not touch any project's node_modules folder or your installed packages.
yarn (v1 Classic)
Yarn Classic stores its cache in a location you can check with:
yarn cache dir
Usually it's ~/Library/Caches/Yarn. Clear it:
yarn cache clean
Yarn v2+ (Berry) uses a different caching model with .yarn/cache inside each project. Those are typically committed to git and should be left alone unless you're cleaning up a project entirely.
pnpm
pnpm uses a content-addressable store — a single shared folder where every package version exists exactly once. Find it:
pnpm store path
Usually ~/.local/share/pnpm/store. To remove packages that no project on your machine references anymore:
pnpm store prune
This is more targeted than a full wipe — it only removes orphaned packages. If you want a complete reset instead:
rm -rf $(pnpm store path)
Cargo (Rust)
Cargo stores downloaded crates and compiled artifacts in ~/.cargo. The two biggest subdirectories are:
~/.cargo/registry— downloaded crate source code and metadata~/.cargo/git— git-based dependencies
Check the total:
du -sh ~/.cargo/registry ~/.cargo/git
Safe to clear:
rm -rf ~/.cargo/registry/cache ~/.cargo/registry/src
This removes cached downloads but keeps the index (the list of what exists on crates.io), so your next cargo build re-downloads only what it needs without re-indexing everything.
If you have cargo-cache installed (cargo install cargo-cache), you can get a nice summary and clean selectively:
cargo cache --autoclean
Gradle (Android / Java / Kotlin)
Gradle stores downloaded dependencies and build caches in ~/.gradle. On a machine that's built Android apps, this folder can easily hit 5–15 GB.
Check the size:
du -sh ~/.gradle/caches
Clear it:
rm -rf ~/.gradle/caches
Your next build will re-download dependencies and rebuild what it needs. The ~/.gradle folder also contains wrapper/ (Gradle versions) and daemon/ (background process logs) — you can leave those alone or delete them too if you want a full reset.
Quick reference
| Tool | Cache location | Clean command |
|---|---|---|
| npm | ~/.npm | npm cache clean --force |
| yarn v1 | ~/Library/Caches/Yarn | yarn cache clean |
| pnpm | ~/.local/share/pnpm/store | pnpm store prune |
| Cargo | ~/.cargo/registry | rm -rf ~/.cargo/registry/cache ~/.cargo/registry/src |
| Gradle | ~/.gradle/caches | rm -rf ~/.gradle/caches |
What to expect after clearing
Nothing will break. Your projects, source code, and configuration are untouched. The only difference:
- First install/build will be slower. The tools need to re-download packages from the internet instead of reading them from the local cache. On a fast connection, this takes seconds to a few minutes depending on project size.
- Subsequent builds go back to normal. The cache starts rebuilding itself immediately as you work.
A note on disk space and Mac performance
Clearing caches won't magically speed up your Mac, but if your startup disk is nearly full, freeing 10–20 GB of cached data can have a noticeable effect. macOS uses free disk space for virtual memory (swap), and when there's not enough room, everything slows down. Developer caches are often the easiest, safest thing to remove when you need space quickly.
Let Gigatidy find all your developer caches
Gigatidy knows where every tool stores its cache, shows you the total size, and cleans them up in one step — no commands to memorize.
Meet Gigatidy →FAQ
Will clearing caches delete my projects or code?
No. Caches contain only downloaded copies of packages from registries like npmjs.com or crates.io. Your source code, configuration files, and project structure are completely separate and unaffected.
How often should I clear developer caches?
There's no strict schedule. A good rule of thumb: check when your disk is getting full, or do a cleanup every few months. If you frequently switch between many projects, caches grow faster.
Can I clear all of these at once?
Yes — you can run the commands back to back in Terminal. Just make sure you're not in the middle of a build or install. Each tool handles its own cache independently, so clearing one has no effect on the others.