How to clear Homebrew, pip and npm caches on a Mac

Package managers keep what they download so the next install is faster, and the downloads add up. Each one has its own command to clear its cache. Read what each removes first: Homebrew’s also removes old versions of what you installed.

Homebrew

Homebrew keeps the installers it downloaded in ~/Library/Caches/Homebrew. brew --cache prints the folder in use. Choose what to remove:

pip

pip keeps downloads and built Python packages, called wheels, in ~/Library/Caches/pip by default. Python installs and virtual environments can share this cache. pip cache dir prints the folder in use. Choose a cleanup command:

npm

npm keeps package data for every project in ~/.npm. The _npx folder inside it holds the packages npx installed to run, and has its own cleanup command. Manage the caches separately:

Advice to skip

Clear cached downloads without removing working environments:

Measure developer caches in Sizewise

Scan your home folder to find which caches take the most space:

A Sizewise window showing a sample home folder as a map: Movies, Library with Developer and CoreSimulator, Pictures and Downloads, each a rectangle sized by the space it takes, with a selected folder outlined and its size in the status bar.

  1. In Sizewise, choose File > Scan Folder and choose your home folder, or scan your whole disk to see the caches next to everything else.
  2. Lock a folder with a click to see what deleting it would free. When that’s less than its size, Sizewise shows what keeps the rest, such as copies that share their data.

Sizewise shows where the space is, and you decide what goes. It asks before every move, and moves files only to the Trash, so you can put them back.

Try it on your Mac

Scanning, saving scans and opening scans are free, with no account. A license costs $12.99 USD once, plus tax where it applies, and adds Move to Trash, Compare with Saved Scan… and Show Changes. Sizewise needs macOS Sequoia or later. See pricing and license details.

Get Sizewise