How to clear npm, yarn, pnpm, cargo and pip caches on Mac

Updated 15 October 2026

Package managers keep a copy of everything they download so the next install is faster. These caches are shared by all your projects, they rarely clean themselves up, and they are safe to clear. Here is where each one lives on macOS and how to clear it properly.

Quick reference

ToolCache locationClear with
npm~/.npm/_cacachenpm cache clean --force
Yarn 1~/Library/Caches/Yarnyarn cache clean
Yarn 2+~/.yarn/berry/cacheyarn cache clean --all
pnpm~/Library/pnpm/storepnpm store prune
Cargo~/.cargo/registry, ~/.cargo/gitdelete by hand
pip~/Library/Caches/pippip3 cache purge

To see several sizes at once (folders you don't have are reported as missing):

du -sh ~/.npm/_cacache ~/Library/Caches/Yarn ~/.yarn/berry/cache ~/Library/pnpm/store ~/.cargo/registry ~/.cargo/git ~/Library/Caches/pip

npm

npm config get cache prints the cache folder, ~/.npm by default. The package data is in ~/.npm/_cacache.

du -sh ~/.npm/_cacache
npm cache clean --force

npm asks for --force because it considers the cache self-healing. npm cache verify is the gentler option: it checks the cache and removes data it no longer needs.

Yarn

Yarn 1 (classic) keeps its cache in ~/Library/Caches/Yarn. yarn cache dir prints the exact path and yarn cache clean empties it.

Yarn 2 and later keep a global cache in ~/.yarn/berry/cache by default. yarn cache clean --all clears it.

Be careful with a .yarn/cache folder inside a project. In projects that use Yarn's zero-installs, that folder is committed to git and the project needs it.

pnpm

pnpm keeps one content-addressable store for all projects. pnpm store path prints its exact location, such as ~/Library/pnpm/store/v10.

du -sh "$(pnpm store path)"
pnpm store prune

pnpm store prune removes packages that no project references. Because each project's node_modules is hard-linked to the store, deleting the store by hand frees less than its size suggests; prune is the intended way. pnpm also keeps a metadata cache in ~/Library/Caches/pnpm, which is safe to delete.

Cargo

Cargo's download cache is in ~/.cargo/registry: index (the registry index), cache (downloaded .crate files) and src (unpacked sources). Git dependencies are in ~/.cargo/git.

du -sh ~/.cargo/registry/* ~/.cargo/git
rm -rf ~/.cargo/registry/cache ~/.cargo/registry/src ~/.cargo/git

Cargo has no stable command for clearing these, so deleting by hand is the usual way. Keeping index means Cargo doesn't fetch the index again from scratch.

Never delete ~/.cargo/bin. It holds tools you installed with cargo install and, with rustup, the cargo and rustc commands themselves. Leave ~/.cargo/config.toml and ~/.cargo/credentials.toml alone too.

pip

pip3 cache dir
pip3 cache info
pip3 cache purge

The cache is in ~/Library/Caches/pip. Clearing it doesn't touch installed packages or your virtual environments. Use pip instead of pip3 if that is what your setup calls it.

What happens after

Nothing in your projects changes. The next install downloads what it needs again, so it needs a network connection and is slower than usual the first time. Offline installs that relied on the cache won't work until it fills back up.

What not to delete

Or let SymbolSweep find it

The free scan in SymbolSweep measures these caches and sorts them by tier:

Download SymbolSweep for Mac

Scanning is free and never deletes anything. Deleting needs a one-time $12 license for one Mac. Requires macOS 13 or later on Apple silicon. See how it works.

FAQ

Is it safe to clear the npm cache?

Yes. It is a download cache. npm fetches anything it needs again on the next install. Use npm cache clean --force, or npm cache verify for a gentler clean.

Will clearing package caches delete my installed packages?

No. Project node_modules folders, global packages, virtual environments and Cargo-installed tools are stored elsewhere and stay put.

Is it safe to delete ~/.cargo?

Not the whole folder. ~/.cargo/registry and ~/.cargo/git are caches, but ~/.cargo/bin holds your installed tools and, with rustup, cargo and rustc themselves.

How do I find where each cache is on my Mac?

Ask the tool: npm config get cache, yarn cache dir, pnpm store path and pip3 cache dir. Cargo always uses ~/.cargo unless CARGO_HOME is set.

Related guides