CleanMate

All guides · macOS and Ubuntu · Updated

Clear the npm, Yarn, pnpm and Bun cache on Mac and Ubuntu: commands and what is safe

Where npm, Yarn, pnpm and Bun keep their package caches on a Mac and on Ubuntu, the commands to clear them (npm cache clean, pnpm store prune, yarn cache clean, bun pm cache rm) and what each one costs you.

Download for macOS · Install on Ubuntu — free and open source

CleanMate on a Mac after a Smart Scan cleanup of the npm, Yarn, pnpm and Bun caches, showing the space freedCleanMate on a Mac after a Smart Scan cleanup of the npm, Yarn, pnpm and Bun caches, showing the space freed

Every JavaScript package manager keeps a copy of each package it downloads, and none of them trims it on its own. After a year of projects the npm cache is 2 to 10 GB, the pnpm store 5 to 30 GB, and Yarn and Bun a few GB each.

All of these caches are safe to clear: the next install downloads what it needs again, only slower and with the network. They are separate from the node_modules folder inside each project, which is what your app actually runs on.

Where each cache is

Tool Mac Ubuntu Ask the tool
npm ~/.npm (_cacache, _npx) ~/.npm npm config get cache
Yarn 1 ~/Library/Caches/Yarn ~/.cache/yarn yarn cache dir
Yarn 2+ (Berry) ~/.yarn/berry/cache ~/.yarn/berry/cache yarn config get cacheFolder
pnpm ~/Library/pnpm/store ~/.local/share/pnpm/store pnpm store path
Bun ~/.bun/install/cache ~/.bun/install/cache bun pm cache

Sizes first, so you know what you win:

du -sh ~/.npm ~/.bun/install/cache 2>/dev/null
du -sh "$(pnpm store path)" 2>/dev/null
du -sh "$(yarn cache dir)" 2>/dev/null

npm

npm cache verify          # checks the cache and removes garbage
npm cache clean --force   # deletes everything

npm cache clean refuses without --force because npm repairs its own cache; deleting it is harmless. The _npx folder inside holds packages that npx ran once; it goes with the rest.

Yarn

yarn cache dir
yarn cache clean          # Yarn 1: everything (or: yarn cache clean <package>)
yarn cache clean --all    # Yarn 2+: the global cache and the project's

A Yarn 2+ project can store its packages inside the repository, in .yarn/cache (Plug’n’Play and zero-installs). Do not delete that folder if it is committed to Git: the project would not run until yarn install fetches everything again. Only the global ~/.yarn/berry/cache is a plain download cache.

pnpm

pnpm store path
pnpm store prune          # removes packages no project uses any more

pnpm links files from its store into each project’s node_modules (hard links, or clones on macOS). Two things follow:

Bun

bun pm cache          # prints the folder
bun pm cache rm       # deletes it

Bun clones files from its cache into node_modules on a Mac (hard links on Linux), so as with pnpm the cache frees less than its size while projects still use those files.

The same cache, one level up

Version managers keep their own downloads: nvm stores installers in ~/.nvm/.cache and every Node version in ~/.nvm/versions. See old runtime versions for those, and stale node_modules and build folders for the bigger prize: the node_modules of projects you no longer touch. For the caches of other ecosystems, see Python caches and Rust, Go and Java package caches.

How CleanMate does it

CleanMate lists these under Smart Scan › Developer Junk, each tool its own item with its size, on a Mac (macOS features) and on Ubuntu (Ubuntu features). Nothing is removed until you confirm.

What CleanMate does not do: it never touches a project’s .yarn/cache, and it does not remove a project’s node_modules unless the project has been idle for 90 days; those are separate items, not ticked, and go to the Trash so a fresh install can bring them back.

FAQ

Is it safe to run npm cache clean --force? Yes. It deletes downloaded tarballs and metadata. The next npm install downloads them again; your projects and global packages stay.

Will clearing the pnpm store break my projects? No. Their node_modules keep working, because the files are linked there too. A later install of a package that is no longer in the store downloads it again.

Why did the cache come back at the same size? Every install refills it. The cache is a copy kept for speed: clear it when you need the space, not as a habit.

Should I clear the cache in CI? Usually not: a restored cache is what makes CI fast. Clear it locally, or change the cache key when a bad entry needs to go.

Skip the commands

CleanMate runs on both systems: pick yours.

Open source — star it on GitHub: CleanMate for macOS · CleanMate for Ubuntu

How CleanMate decides what is safe to remove →