Developer Mac

How to Clear npm, Yarn, pnpm and Bun Caches on Mac

How to clear npm, Yarn, pnpm and Bun caches on a Mac safely: where each cache lives, how to check its size first, and the right command for each tool.

By Surendra Pandar, maker of DiskMate 7 min read

I measured my own Mac on 10 November 2026. The npm cache in ~/.npm was 6.4 GB, and the pnpm folder in ~/Library/pnpm was 1.9 GB. That is 8.3 GB of downloaded packages that I never see in Finder.

That is on my 1 TB Mac, where it is easy to ignore. On a 256 GB Mac, 8.3 GB is about 3% of the whole disk. I don't use Yarn or Bun on this Mac, so for those two I go by their official docs, which I link below.

Your list will not match mine. You may see other folders, and that is fine. Use the same steps.

Is it safe to clear these caches?

Yes. A package cache is a pile of downloads. When you install a package, the tool keeps a copy so the next install is faster. Clearing the cache does not touch your code, your lockfiles or the node_modules folders inside your projects.

You do lose two things:

  • Speed on the next install. Packages are downloaded again instead of copied from disk.
  • Offline installs. With an empty cache you need a connection to install anything.

One thing worth knowing about npm: its own docs say the cache is self-healing, and that clearing it should never be necessary “for any reason other than reclaiming disk space”. So if a build is broken, the cache is rarely the cause. If your disk is full, it is a fair thing to clear. The same page says npm will not remove data by itself, so the cache only grows.

Where each cache lives on a Mac

These are the default places, taken from each tool's docs. A setting or environment variable can move them, so the command in the third column is the reliable way to find yours.

ToolDefault placePrint the real pathClear it
npm~/.npmnpm config get cachenpm cache clean --force
pnpm~/Library/pnpm/storepnpm store pathpnpm store prune
Yarn 1 (Classic)A global cache in your user folderyarn cache diryarn cache clean
Yarn 2 and newerInside ~/.yarn/berryyarn config get globalFolderyarn cache clean --mirror
Bun~/.bun/install/cachebun pm cachebun pm cache rm

Sources: npm cache, pnpm store settings, Yarn Classic cache, yarn cache clean, Yarn settings and Bun global cache.

Check the size first, then clear

See how big each cache is

Open Terminal and measure before you delete. du -sh only adds up a folder's size. Run the lines for the tools you have and skip the rest:

Terminal
$ du -sh ~/.npm$ du -sh "$(pnpm store path)"$ du -sh "$(yarn cache dir)"$ du -sh "$(bun pm cache)"
Read-only. Each line prints one size. A line for a tool you don't have just prints an error, which is fine.

I check my own Mac with a small script that runs du -sh on a list of folders. These are its two lines for the tools I use:

Terminal
$ bash measure-dev-storage.sh~/.npm                        6.4Gpnpm store (~/Library/pnpm)   1.9G
Output from my 1 TB Mac, November 2026. The script is my own. The du lines above give you the same kind of numbers.

If a cache is a few hundred megabytes, leave it. It is saving you time. If it is several gigabytes and you need the room, go on.

npm: verify first, clean if you need more

npm has a gentle option and a full one. npm cache verify checks the cache and removes data it no longer needs. It keeps everything that is still valid, so installs stay fast:

Terminal
$ npm cache verify
Checks the cache and garbage-collects unneeded data. Keeps valid packages.

Run the du line again. If it is still too big, empty it fully:

Terminal
$ npm cache clean --force
Deletes every package in npm's cache. There is no undo, but npm downloads what it needs on the next install.

pnpm: prune the store

pnpm works differently. It keeps one copy of every package in a store and hard-links it into each project, so the same package in ten projects takes the space of one. That means you should not empty the store by hand. Use prune, which only removes packages that no project on your Mac uses:

Terminal
$ pnpm store prune
Removes unreferenced packages from the pnpm store. Projects that still use a package keep it.

pnpm's store docs say this “is not harmful and has no side effects on your projects”. Prune works best after you delete old projects or their node_modules folders, because that is what makes packages unreferenced. I cover that in How to Find and Delete Every node_modules Folder on Mac.

Yarn: one command, two versions

Run yarn --version first. If it starts with 1, you have Yarn Classic, and this clears its global cache:

Terminal
$ yarn cache clean
Yarn 1 only. Clears the global cache. It fills again the next time you run yarn install.

Yarn 2 and newer keeps a global cache inside ~/.yarn/berry by default, shared by all your projects. Its docs describe plain yarn cache clean as removing the local cache files. To remove the global ones, add a flag:

Terminal
$ yarn cache clean --mirror
Yarn 2 and newer. --mirror removes the global cache files. Use --all to remove the global files and the current project's files.

Bun: preview, then remove

Bun can show you what it would do before it does it:

Terminal
$ bun pm cache rm --dry-run$ bun pm cache rm
The first line only previews. The second clears Bun's global cache.

Bun's docs also list bun pm cache prune, which only removes packages older than 30 days by default.

What my numbers mean on a smaller disk

The same cache hurts more on a smaller disk. Here are my sizes as a share of the three common Mac disk sizes. This is plain division, and your sizes will differ:

On my 1 TB MacSizeShare of 256 GBShare of 512 GBShare of 1 TB
npm cache6.4 GB2.5%1.3%0.6%
pnpm folder1.9 GB0.7%0.4%0.2%
Both8.3 GB3.2%1.6%0.8%

A cache is not sized by your disk. It is sized by how many packages you have installed over time. So a 256 GB Mac used for the same work can hold the same 8 GB of cache, with far less room to spare.

How often should you clear them?

Not often. A cache is doing its job when it is full of things you use. Clear it when you need the space, not on a timer. pnpm's docs give the same advice for prune: run it occasionally, but not too frequently.

If your disk is still tight after this, the caches were not the main problem. Old node_modules folders are the next place to look, and after that it is the rest of your disk. Start with How to Free Up Space on Mac.

The faster way: all of them in one list

Four tools means four commands and four places to check. DiskMate, the Mac app I make, does it in one window. Its developer cleanup looks in the npm, pnpm, Yarn and Bun cache folders, shows the size of each next to your node_modules and build folders, and moves what you tick to the Trash, so you can put it back.

The commands above are free and do the job. The app is for when you would rather see it all at once.

See every package cache and its size in one window.
DiskMate lists package caches, node_modules and build folders with their sizes, and moves only what you tick to the Trash. $5 once, no subscription.
Get DiskMate for $5Pay once · No subscription · Works offline

Frequently asked questions

How do I clear the npm cache on a Mac?+

Open Terminal and run npm cache clean --force. It deletes everything in npm's cache, which is in ~/.npm by default on a Mac. For a gentler cleanup, run npm cache verify, which removes unneeded data and checks the rest.

Is it safe to delete the npm cache?+

Yes. The npm cache only holds copies of packages npm has downloaded. Your projects and their node_modules folders are not touched. The cost is that the next install has to download those packages again, so it is slower and needs a connection.

Why does npm cache clean need --force?+

npm's docs say the cache is self-healing and that clearing it should never be necessary for any reason other than reclaiming disk space. The --force flag is npm's way of making sure you mean it. Freeing disk space is a valid reason.

What does pnpm store prune do?+

pnpm store prune removes packages from pnpm's store that no project on your Mac uses any more. pnpm's docs say it is not harmful and has no side effects on your projects. If a later install needs a removed package, pnpm downloads it again.

Where is the pnpm store on a Mac?+

By default the pnpm store is in ~/Library/pnpm/store on macOS. Run pnpm store path to print the exact folder on your Mac, because the PNPM_HOME and XDG_DATA_HOME settings can move it.

Does clearing the npm cache delete node_modules?+

No. node_modules folders live inside each project and are separate from the cache. Clearing the cache does not change them, and deleting node_modules does not clear the cache. To get all the space back you need to do both.

How do I clear the Bun cache on a Mac?+

Run bun pm cache rm. It clears Bun's global cache, which is in ~/.bun/install/cache by default. Run bun pm cache rm --dry-run first if you want to see what it would do, and bun pm cache to print the folder.

Written by Surendra Pandar
I build DiskMate, a small Mac app for finding and clearing disk space. I wrote this guide from the same research that went into the app. Spotted something wrong or out of date? Email surendrapandar.work@gmail.com or find me on X.

Keep reading