Guide

How to clear npm, Yarn, pnpm, Bun and Homebrew caches on a Mac

The exact commands to clear npm, Yarn, pnpm, Bun, Homebrew and pip caches on a Mac, where each cache lives, and what is safe to delete.

Updated 6 min read

Package managers keep a copy of everything they download, so installs are faster next time. After a year of projects, those caches can reach tens of gigabytes. Every one of them is safe to clear: the next install simply downloads what it needs. Here are the exact commands for the common ones on a Mac.

npm

The cache lives in ~/.npm/_cacache. Check and tidy it, or clear it completely:

npm cache verify
npm cache clean --force

Yarn

Yarn 1 (classic):

yarn cache dir
yarn cache clean

Yarn 2 and later:

yarn cache clean --all

pnpm

pnpm keeps a shared store. Remove packages no project uses any more:

pnpm store path
pnpm store prune

Bun

Bun's cache is in ~/.bun/install/cache:

bun pm cache rm

Homebrew

Remove old versions and stale downloads, preview first if you like, and remove dependencies nothing needs any more:

brew cleanup -n
brew cleanup
brew cleanup --prune=all
brew autoremove

brew --cache shows where downloads are kept.

pip

pip cache dir
pip cache purge

CocoaPods and Swift Package Manager

Clear the CocoaPods cache with pod cache clean --all. Swift Package Manager keeps downloaded packages in ~/Library/Caches/org.swift.swiftpm, which you can delete while Xcode is closed.

Old node_modules folders

Projects you haven't touched in months often hold large node_modules folders. To list them with their sizes:

find ~/Projects -name node_modules -type d -prune -exec du -sh {} + | sort -h

Change ~/Projects to wherever you keep your code. Deleting a project's node_modules is safe; run an install to get it back.

Find every cache at once with Roomy

Roomy's Developer cleanup finds npm, Yarn, pnpm, Bun, Deno, Homebrew, pip, Poetry, uv, CocoaPods, Carthage, Swift Package Manager, Gradle, Maven, Cargo and Go caches in one scan, with each one's size. Most package caches are rated Safe because they download again; a few that are slow to fetch again, such as the pnpm store and Gradle caches, are rated Review. Your projects are never touched.

Frequently asked questions

Is it safe to clear the npm cache?

Yes. The npm cache only holds copies of packages npm downloaded. Your projects and their node_modules folders aren't affected, and npm downloads anything it needs again on the next install.

What does brew cleanup remove?

Old versions of installed formulae and casks, and downloads in the Homebrew cache older than 120 days. Add --prune=all to remove all cached downloads, or -n to preview what it would delete.

Should I delete node_modules folders?

In projects you aren't working on, yes: npm, Yarn, pnpm or Bun recreate them with an install. Don't delete node_modules of a project that is running, and keep your lockfile so the install gives the same versions.

Give your Mac room to breathe.
Start with a free scan.

Download Roomy, see exactly what is taking up space, and clean up to 500 MB for free. Nothing is removed until you say so.

Version 1.0.0 5 MB macOS 14 Sonoma or later Apple silicon and Intel