Node.js ecosystem disk

Yarn Cache Eating Your Disk? How to Clear It on macOS

If you have been using Yarn for a while on macOS, its global cache can quietly grow to several gigabytes without you realizing it. Knowing how to clear yarn cache properly — and safely — requires understanding which version of Yarn you are running, where it stores its files, and what the difference is between the built-in command and a manual deletion.

Yarn Classic vs Yarn Berry: Different Caches, Different Paths

Yarn has two very different major versions in widespread use, and they cache files in separate locations. Before you run any cleanup command, confirm which version you are using:

yarn --version
  • 1.x — Yarn Classic
  • 2.x, 3.x, 4.x — Yarn Berry

The cache behavior and commands differ enough that conflating them causes confusion. The sections below cover each separately.

Yarn Classic Cache (v1.x)

Where is the Yarn Classic cache on macOS?

Yarn Classic stores its global package cache inside the macOS user Caches directory. To find the exact path on your machine:

yarn cache dir

The default output is typically:

/Users/yourname/Library/Caches/Yarn/v6

You can open it directly in Finder:

open "$(yarn cache dir)"

How to check the Yarn cache size

Before wiping anything, it is worth knowing how much space you are actually dealing with:

du -sh "$(yarn cache dir)"

On an active development machine this directory commonly reaches 2–8 GB depending on how many projects and how many package versions have been installed over time.

How to clear Yarn Classic cache

The recommended way is the built-in command:

yarn cache clean

This removes all cached packages from the global cache directory. Yarn will re-download packages from the registry the next time you run yarn install in any project. Your node_modules folders and yarn.lock files are not touched — only the global download cache is deleted.

You can also remove the cache for a single package if you want to force a fresh download of just one dependency:

yarn cache clean <package-name>

Manual deletion (when the command fails)

If Yarn itself is broken or you prefer a direct approach:

  1. Find the cache directory: yarn cache dir
  2. Delete it: rm -rf "$(yarn cache dir)"
  3. Yarn will recreate the directory structure on the next install.

This is safe because the Yarn Classic cache is purely a download cache — nothing in it is the authoritative copy of your code or configuration.

Yarn Berry Cache (v2, v3, v4)

Where is the Yarn Berry cache on macOS?

Yarn Berry stores its global cache in a different location by default:

yarn cache dir

On macOS this typically resolves to:

/Users/yourname/Library/Caches/Yarn/Berry

However, Yarn Berry is highly configurable. If your project or global .yarnrc.yml overrides globalFolder, the cache location changes. Always run yarn cache dir to confirm.

Yarn Berry also supports Plug'n'Play (PnP)

If your project uses Plug'n'Play mode (the default in newer Berry projects), packages are not stored in node_modules at all — they live in .yarn/cache inside the project directory as zip archives. This is a per-project cache, not a global one. Deleting it forces Yarn to unpack packages again but does not lose anything permanent, because the zip files are usually committed to the repository (zero-install workflow) or can be re-fetched.

To clear the Berry global cache:

yarn cache clean --all

Comparison: Yarn Classic vs Yarn Berry Cache

Property Yarn Classic (v1) Yarn Berry (v2–4)
Default cache path ~/Library/Caches/Yarn/v6 ~/Library/Caches/Yarn/Berry
Clean command yarn cache clean yarn cache clean --all
Per-project cache No Yes (.yarn/cache in project)
PnP mode No Yes (optional, often default)
Safe to delete? Yes — regenerable Yes — regenerable (except zero-install zips you intend to keep committed)

Is It Actually Safe to Delete the Yarn Cache?

In almost every case, yes. The global Yarn cache is a download cache — Yarn keeps copies of packages there so it does not need to hit the network on every fresh install. Deleting it has two consequences:

  • Your next yarn install in any project will be slower because packages must be re-downloaded.
  • Nothing else breaks. Your code, lock files, and node_modules directories are unaffected.

If you are not certain what a particular directory under ~/Library/Caches is — or whether something inside it is safe to remove — Crumb's built-in AI can help. Select any folder in Crumb's Visualize view and ask "Is this safe to delete?" Crumb explains what the folder is for and whether its contents are regenerable, so you can make an informed decision before wiping anything. It is especially useful when you encounter unfamiliar cache directories from tools like Yarn, pnpm, Bun, or CocoaPods sitting side by side.

Cleaning node_modules Is a Separate Step

Clearing the Yarn cache does not remove node_modules from your projects. If you want to free space from project dependencies too, you need to do that separately — either manually or with a tool like npx npkill to scan for and remove abandoned node_modules folders across your filesystem.

A quick one-liner to see your largest node_modules directories:

find ~ -name "node_modules" -type d -prune -print | xargs du -sh 2>/dev/null | sort -hr | head -20

This gives you a ranked list of the biggest offenders so you know where to focus.

How Much Space Can You Reclaim?

This varies entirely by how long you have been using Yarn and how many projects you maintain. The Yarn cache deduplicates package versions across projects — a package at a given version is only stored once globally — so the savings from clearing it represent cached downloads, not unique data you cannot get back.

Common space recovered from the global Yarn cache alone:

  • Light use (a few projects): 200 MB–1 GB
  • Active developer (many projects, years of use): 3–10 GB
  • Monorepo with many lockfile resolutions over time: can exceed 10 GB

If you want a visual breakdown of exactly what is eating your disk — not just Yarn but everything — download Crumb and use its disk map to see the full picture at a glance, then drill into caches and development directories to decide what to clear.

Quick Reference: Commands to Clear Yarn Cache on macOS

  1. Check your Yarn version: yarn --version
  2. Find the cache location: yarn cache dir
  3. Check the size: du -sh "$(yarn cache dir)"
  4. Clear it (Classic): yarn cache clean
  5. Clear it (Berry): yarn cache clean --all
  6. Verify it is gone: du -sh "$(yarn cache dir)"

Clearing the Yarn cache is one of the lower-risk disk cleanup tasks on a developer Mac — the data is transient by design and Yarn regenerates it automatically. The main cost is a slower first install afterward, which is usually a worthwhile trade for recovering several gigabytes of space.

Reclaim your disk in one click

Crumb audits your whole Mac, tells you what's safe to delete, and frees the space in seconds — private, local, and Apple-notarized.

Download Crumb for macOS

Frequently asked questions

Is it safe to delete the Yarn cache on macOS?
Yes. The Yarn global cache is a download cache that Yarn regenerates automatically on the next install. Deleting it does not affect your code, lock files, or node_modules directories. The only side effect is a slower first yarn install afterward while packages are re-downloaded.
Where is the Yarn cache stored on macOS?
Yarn Classic (v1) stores its cache at ~/Library/Caches/Yarn/v6 by default. Yarn Berry (v2–4) uses ~/Library/Caches/Yarn/Berry. Run `yarn cache dir` in your terminal to confirm the exact path on your machine.
What is the difference between `yarn cache clean` and deleting the cache folder manually?
`yarn cache clean` is the official command and cleanly removes cached packages through Yarn's own logic. Manually deleting the folder with `rm -rf` achieves the same end result — both approaches are safe — but the manual method is useful when Yarn itself is not functioning correctly.
Does clearing the Yarn cache also delete node_modules?
No. The Yarn global cache and your project node_modules directories are entirely separate. Clearing the cache only removes Yarn's global download store. Each project's node_modules folder is unaffected and must be deleted separately if you want to free that space too.
How do I check how large my Yarn cache is?
Run `du -sh "$(yarn cache dir)"` in Terminal. This prints the total size of your Yarn cache directory so you know how much space you stand to recover before deleting it.