ElfClean

ElfClean / Guides

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:

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

ToolCache on macOSSee itClear it
pip~/Library/Caches/pippip cache dir, pip cache infopip cache purge
uv~/.cache/uvuv cache dir, uv cache size -Huv cache prune or uv cache clean
Poetry~/Library/Caches/pypoetrypoetry cache listpoetry 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

ToolCache on macOSClear it with
Gradle~/.gradle/caches and ~/.gradle/wrapper/distsNo command; stop daemons with ./gradlew --stop, then delete the folders.
CocoaPods~/Library/Caches/CocoaPodspod cache list, then pod cache clean --all
Swift packages~/Library/Caches/org.swift.swiftpmswift 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

ManagerCacheClear it with
npm~/.npm/_cacachenpm cache clean --force
pnpm~/Library/pnpm/storepnpm store prune
Yarn~/Library/Caches/Yarnyarn cache clean
Bun~/.bun/install/cachebun 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