Cleaning up Homebrew, pip and other package caches

Photo: Kindel Media on Pexels

Every package manager keeps a copy of what it downloads, and none of them is in a hurry to throw it away. Here is where each cache lives, how to check its size, and the one-liner that clears it.

Updated October 2026 6 min readmacOS 15 to 27

Why package caches are safe to clear

A package cache is a local copy of things that also exist on a registry: tarballs from npm, wheels from PyPI, bottles from Homebrew. The package manager keeps them so the next install is faster and works offline.

That makes them safe to clear. Nothing in a cache is the only copy. The cost is time: the next install downloads again, and you need a network connection for it. On a fast connection that is a minor inconvenience; on a train it is a reason to wait.

Before clearing anything, it helps to see which caches are large. This checks the usual places in one go:

~ % du -sh ~/Library/Caches/{Homebrew,pip,Yarn,CocoaPods,go-build} \
    ~/.npm ~/.yarn/berry/cache ~/Library/pnpm/store \
    ~/.gradle/caches ~/.cargo/registry ~/go/pkg/mod 2>/dev/null | sort -h

Folders that do not exist on your Mac are skipped. The sections below cover each tool, with the command that asks the tool where its cache is, in case you changed the default.

Homebrew

Homebrew keeps downloaded bottles and source archives in ~/Library/Caches/Homebrew (brew --cache prints the path), plus old versions of upgraded formulae.

# show what would be removed
~ % brew cleanup -n
# remove old versions and downloads older than 120 days
~ % brew cleanup
# remove every cached download
~ % brew cleanup --prune=all

Homebrew also runs this cleanup on its own, at most every 30 days, when you install or upgrade something. It only removes downloads older than 120 days, so the cache can still be several gigabytes. --prune=all keeps everything that is installed and only removes the cached files.

npm, Yarn and pnpm

The three JavaScript package managers each keep their own cache, and a Mac used for web work often has all three.

npm

npm’s cache lives in ~/.npm/_cacache (npm config get cache shows the parent folder). npm cache verify removes data that is no longer needed and checks the rest; npm cache clean --force empties it.

~ % npm cache verify
~ % npm cache clean --force

The --force is required on purpose: npm wants you to know that its cache is self-healing and rarely needs clearing. Packages run with npx are kept separately in ~/.npm/_npx, which you can delete whenever no npx command is running.

Yarn

Yarn 1 (Classic) and Yarn 2 and later (Berry) use different caches.

# Yarn 1: show the cache folder, then clear it
~ % yarn cache dir
~ % yarn cache clean
# Yarn 2 and later: clear the shared cache in ~/.yarn/berry
~ % yarn cache clean --mirror

On Yarn 1, the cache lives in ~/Library/Caches/Yarn. On current Yarn versions, packages are stored once in a global cache at ~/.yarn/berry/cache. Inside a project, yarn cache clean removes the project’s local cache, and yarn cache clean --all removes both. A project that commits its cache for zero installs keeps it in .yarn/cache; leave that one alone, because it is part of the repository.

pnpm

pnpm keeps a content-addressable store, on a Mac usually in ~/Library/pnpm/store. Every project links into it, so clearing it completely would break every project’s node_modules. Instead, prune the packages no project uses anymore:

~ % pnpm store path
~ % pnpm store prune

Do not run pnpm store prune while an install is in progress.

pip and uv

pip keeps downloaded wheels and HTTP responses in ~/Library/Caches/pip.

~ % pip cache info
~ % pip cache purge

If your Mac has several Python installations, each pip reports the same cache folder unless one is configured differently. Use python3 -m pip cache purge to be sure you call the pip you expect.

uv keeps a much larger cache, because it also stores unpacked packages:

~ % uv cache dir
# remove unused entries only
~ % uv cache prune
# remove everything
~ % uv cache clean

Poetry keeps its cache in ~/Library/Caches/pypoetry, and poetry cache clear pypi --all clears the PyPI part.

CocoaPods and Swift Package Manager

CocoaPods stores downloaded pods in ~/Library/Caches/CocoaPods:

~ % pod cache list
~ % pod cache clean --all

The Pods folder inside each project is separate. It comes back with pod install, much like node_modules.

Swift Package Manager caches package repositories in ~/Library/Caches/org.swift.swiftpm. swift package purge-cache clears it. For Xcode’s own build data, see How to clear Xcode DerivedData, archives and simulators.

Gradle and Maven

Gradle keeps dependencies in ~/.gradle/caches and downloaded Gradle versions in ~/.gradle/wrapper/dists. Current Gradle versions remove cache entries that have not been used for a while, but old Gradle versions you no longer use leave their folders behind.

# stop running Gradle daemons first
~/Projects/app % ./gradlew --stop
~ % trash ~/.gradle/caches

Gradle has no command that empties its cache, so deleting the folder is the usual way. The next build downloads everything again, which can take a while for a large Android project. Maven’s equivalent is ~/.m2/repository, which you can remove the same way, keeping any settings.xml in ~/.m2.

Cargo and Go

Cargo keeps downloaded crates in ~/.cargo/registry and git dependencies in ~/.cargo/git. Since Rust 1.88, Cargo removes entries it has not used for months on its own. To clear it now, delete the cache folders and keep the rest of ~/.cargo, which holds your installed tools:

~ % trash ~/.cargo/registry/cache ~/.cargo/registry/src ~/.cargo/git/checkouts

Project build output in each target folder is usually much larger than the registry. cargo clean inside a project removes it.

Go has a built-in command for both of its caches:

# build cache, in ~/Library/Caches/go-build
~ % go clean -cache
# downloaded modules, in ~/go/pkg/mod
~ % go clean -modcache

Use go clean -modcache rather than deleting the folder: Go marks module files read-only, so a plain delete fails with permission errors.

How often to clear caches

You do not need a schedule. A warm cache saves time every day, and clearing every cache at once means every project downloads everything again. A better habit:

  1. Check sizes with the du command above when space gets tight.
  2. Clear the two or three largest caches.
  3. Prefer the gentle commands (brew cleanup, pnpm store prune, uv cache prune) over full clears.

The trash command used above is included with macOS 15 and later. Items you move to the Trash free their space once you empty it.

Was this guide helpful?