Is ~/.yarn Safe to Delete? How to Clear the Yarn Cache on a Mac

Yes, with the right methodDiskmack safety tier: Safe to clean
~/.yarn

Yes, clearing the Yarn cache is safe, and the supported way is one command: yarn cache clean. The bulk of ~/.yarn is packages Yarn already downloaded and can fetch again from the registry, so your next yarn install re-downloads whatever your projects actually need. If your Mac is out of space and this folder has ballooned, it's a reasonable place to reclaim gigabytes.

What it is

~/.yarn is a hidden folder in your home directory where the Yarn package manager keeps its global data. What lands there depends on which Yarn you run. Modern Yarn (version 2 and later) stores its shared download cache at ~/.yarn/berry/cache: each package it fetches is saved there as a compressed archive so the next project that needs the same version can copy it from disk instead of pulling it from the npm registry again. If you installed the old Yarn 1 with its shell installer, the yarn program itself also sits in ~/.yarn/bin.

The catch is that the global cache only grows. Every version of every package from every project stays there, and Yarn never prunes it on its own. Work on a few JavaScript projects for a year and the folder quietly accumulates hundreds of megabytes, often several gigabytes on machines that touch a lot of repos. Yarn 1 is the odd one out: on a Mac it keeps its package cache at ~/Library/Caches/Yarn instead, so if your ~/.yarn is huge, a version 2 or later Yarn put it there.

Is it safe to delete?

This folder is in the safe tier. Deleting it loses nothing you can't get back: the contents regenerate on your next yarn install, because Yarn just re-downloads packages from the registry as projects need them. The only real cost is bandwidth and a slower first install after the wipe. Projects that install into node_modules, which is most of them, keep running untouched because they have their own copies. Projects using Yarn's Plug'n'Play mode load packages straight from the cache, so those will error until you run yarn install again, and then they're fine.

There is one reason to prefer the official command over dragging the folder to the Trash. If you installed Yarn years ago with its curl-based shell installer, the yarn program itself lives at ~/.yarn/bin, and trashing the whole folder removes Yarn along with the cache. Installs done through Homebrew, npm, or Corepack don't have this problem, but yarn cache clean sidesteps the question entirely: it removes cached packages and nothing else. Diskmack identifies this folder automatically and cleans it the safe way.

How to check its size

In Finder: In Finder, choose Go > Go to Folder (or press Command+Shift+G), type ~/.yarn and press Return. Then press Command+I to open Get Info and wait for the size to calculate.

In Terminal:

du -sh ~/.yarn

The ~ expands to your home folder automatically, so no quoting is needed.

How to clean it

  1. Finish or cancel any yarn install that's currently running in a terminal.
  2. In Finder, press Command+Shift+G, type ~ and press Return to open your home folder.
  3. Press Command+Shift+Period to show hidden files. The .yarn folder appears, slightly grayed out.
  4. Click .yarn once to select it, then press Command+I if you want to see how much space you're getting back.
  5. Drag .yarn to the Trash and empty the Trash. Press Command+Shift+Period again to re-hide hidden files.

The official way: this tool ships its own cleanup command, which handles locks and indexes correctly.

yarn cache clean

If you installed Yarn with its old shell installer, the yarn binary lives in ~/.yarn/bin, and deleting the whole folder removes Yarn itself. Running yarn cache clean instead clears only the cached packages.

Will it come back?

Yes, and that's by design. The cache starts refilling the next time you run yarn install or yarn add, because Yarn saves a copy of everything it downloads. How fast it grows depends on how many projects you touch and how often their dependencies change. If you've stopped using Yarn, the folder stays empty after a clean. If you use it daily, expect the size to creep back over weeks or months, at which point you can simply clear it again.

Common questions

Will clearing the Yarn cache break my projects?

Almost never. Projects that install into node_modules keep their own copies of every package, and for them the cache exists only to make installs faster. The one exception is projects on Yarn's Plug'n'Play mode, which load packages straight from the cache: those will refuse to run until you do a fresh yarn install. Either way, one slower install re-downloads everything and you're back to normal.

How big does the Yarn cache get?

It depends on how many projects and package versions you've installed over time. A few hundred megabytes is typical, and heavy JavaScript setups can reach several gigabytes. Run du -sh ~/.yarn to see your actual number.

Is yarn cache clean better than deleting the folder in Finder?

Usually, yes. It's the tool's own command, it removes only cache files, and it can't accidentally take out the yarn binary if you installed Yarn with its shell installer. Use Finder if you don't have a working terminal habit and you know Yarn came from Homebrew, npm, or Corepack.

My Yarn cache isn't in ~/.yarn. Where is it?

Yarn 1 on macOS keeps its package cache at ~/Library/Caches/Yarn, not in ~/.yarn. Yarn 2 and later use ~/.yarn/berry/cache for the shared global cache, and some projects keep a per-project cache at .yarn/cache inside the repo instead. Running yarn cache clean inside a project clears whichever cache that project's Yarn version actually uses.

Related folders