How to clear pip, uv, Homebrew, Cargo and other developer caches on a Mac
Every package manager keeps a shared cache of what it downloaded, so the next install is faster. None of them shrink much by themselves, and after a year of trying out tools and AI-generated projects they can add up to tens of gigabytes. Here's where each one lives on macOS and the command its makers give you to clear it.
Is it safe to clear them?
Yes, for everything on this page. These caches hold copies of things you can download again. Your projects and installed environments aren't inside them. Clearing one costs you two things:
- Time and bandwidth. The next install or build downloads, and sometimes compiles, what it needs again.
- Working offline. Until you've reconnected and installed again, a project that needs something you cleared won't build. Clear caches before a flight's worth of work, not during it.
Quit editors and stop running builds first. A package manager halfway through an install can be left confused if its cache vanishes under it.
See how big they are
One command for the usual places:
du -sh ~/Library/Caches/{pip,pypoetry,Homebrew,CocoaPods,org.swift.swiftpm,go-build} \
~/.cache/{uv,pre-commit} ~/.cargo/{registry,git} ~/go/pkg/mod ~/.gradle/{caches,wrapper} \
2>/dev/null | sort -h
Missing folders are skipped. If you've moved a cache with an environment variable or a config file, ask the tool where it is with the commands below.
Python: pip, uv and Poetry
| Tool | Cache on macOS | See it | Clear it |
|---|---|---|---|
| pip | ~/Library/Caches/pip | pip cache dir, pip cache info | pip cache purge |
| uv | ~/.cache/uv | uv cache dir, uv cache size -H | uv cache prune or uv cache clean |
| Poetry | ~/Library/Caches/pypoetry | poetry cache list | poetry cache clear pypi --all |
Use python3 -m pip if there's no pip command, and run it with each Python you use, since they normally share one cache. pip cache remove <package> clears a single package.
uv cache prune removes only entries nothing uses any more, and is the gentler choice. uv cache clean removes everything; add package names to clear just those. Virtual environments uv already made keep working either way. Python versions uv installed live in ~/.local/share/uv/python, not the cache.
Poetry names each cache after its source. poetry cache list shows them, usually just pypi. Without --all, poetry cache clear expects a single package and version.
Homebrew
brew --cache # ~/Library/Caches/Homebrew
brew cleanup --dry-run # what would go
brew cleanup --prune=all
brew cleanup also removes old versions of installed formulae from /opt/homebrew (or /usr/local on Intel Macs), which is often more space than the downloads. --prune=all removes every cached download, not only old ones. Installed software keeps working; reinstalling something downloads it again.
Homebrew also runs a cleanup by itself every 30 days. Downloads for the versions you have installed can be kept; to remove everything, Homebrew's own help suggests rm -rf "$(brew --cache)".
Rust: Cargo
Cargo keeps downloaded crates in ~/.cargo/registry (cache holds the compressed downloads, src the unpacked copies) and Git dependencies in ~/.cargo/git. Cargo has no command of its own to clear them. Recent versions remove downloads that haven't been used for a few months on their own, but only slowly.
du -sh ~/.cargo/registry ~/.cargo/git
rm -rf ~/.cargo/registry/cache ~/.cargo/registry/src ~/.cargo/git/checkouts
Leave ~/.cargo/bin and your config alone: those are your installed tools and settings. cargo cache is a third-party command (cargo install cargo-cache), not part of Cargo; it shows sizes and has an --autoclean option. The biggest Rust folders are usually each project's own target folder, which cargo clean removes.
Go
go env GOCACHE GOMODCACHE
go clean -cache # compiled packages, ~/Library/Caches/go-build
go clean -modcache # downloaded modules, ~/go/pkg/mod
The build cache is safe to clear at any time; builds and tests are slower once. The module cache needs a connection to fill again. Go marks module files read-only, so use go clean -modcache rather than rm -rf, which stops with permission errors.
Gradle, CocoaPods and Swift packages
| Tool | Cache on macOS | Clear it with |
|---|---|---|
| Gradle | ~/.gradle/caches and ~/.gradle/wrapper/dists | No command; stop daemons with ./gradlew --stop, then delete the folders. |
| CocoaPods | ~/Library/Caches/CocoaPods | pod cache list, then pod cache clean --all |
| Swift packages | ~/Library/Caches/org.swift.swiftpm | swift package purge-cache |
Gradle tidies entries it hasn't used for a while by itself, but each Gradle version a project's wrapper downloads stays in wrapper/dists, often several hundred megabytes each. Keep ~/.gradle/gradle.properties, which may hold your settings and credentials. For Xcode's own build folders, see clearing Xcode DerivedData.
JavaScript: npm, pnpm, Yarn and Bun
| Manager | Cache | Clear it with |
|---|---|---|
| npm | ~/.npm/_cacache | npm cache clean --force |
| pnpm | ~/Library/pnpm/store | pnpm store prune |
| Yarn | ~/Library/Caches/Yarn | yarn cache clean |
| Bun | ~/.bun/install/cache | bun pm cache rm |
The shared caches are usually smaller than the node_modules folders in each project. See how to delete old node_modules folders.
pre-commit
pre-commit gc # environments no config uses any more
pre-commit clean # everything in ~/.cache/pre-commit
pre-commit keeps a copy of every hook repository your configs name, each with its own environment. After clean, the next commit in each repository installs its hooks again, which takes a while and needs a connection.
How ElfClean does it
ElfClean finds the package caches for npm, pnpm, Yarn, Bun, pip, uv, Poetry, Cargo, Go, Gradle, CocoaPods, Swift packages, Homebrew and pre-commit in the locations above, and says in plain language what each one is, what happens if it's removed and how it comes back. Caches that rebuild themselves are marked Safe. Go's module cache is marked Review, because builds that need it fail offline until you download again.
It also finds build folders and virtual environments inside projects you haven't touched for a while. Homebrew's old installed versions live outside your home folder, so ElfClean can't remove them; its "Reclaim with the tool's own command" section on the AI & coding screen gives you brew cleanup --prune=all to copy into Terminal instead.
Running tools are left alone. Everything goes to the Trash, and History can put it back.
More guides
- How to delete old node_modules folders on a Mac safely
- Where Ollama and Hugging Face store models on a Mac, and how to remove them
- What Claude Code, Codex and Cursor leave on your Mac
- How to clear Xcode DerivedData, simulators and device support
- What System Data is on a Mac, and how to make it smaller
- How to find large files and duplicates on a Mac
- How to free up Docker disk space on a Mac
- Mac cleaners for developers compared: CleanMyMac alternatives