Is it safe to delete the Yarn cache on Mac?
Safe with care~/.yarn
Yes, with care. Where Yarn 1 and Yarn 2+ keep their caches on a Mac, how to measure them, and the yarn cache clean commands to use instead of rm.
Verdict: Safe with care. Yarn's caches only hold package archives it can download again, so clearing them is safe, but use yarn cache clean rather than deleting ~/.yarn wholesale. That folder can also hold Yarn 2+'s global files and, in some setups, the links to your globally installed tools.
What lives in ~/.yarn, and where Yarn 1 keeps its cache
Two quite different tools share the Yarn name, and they keep their caches in different places.
Yarn 1 (Classic) keeps one global cache. On a Mac it is usually ~/Library/Caches/Yarn, and some setups use ~/.cache/yarn instead. Run yarn cache dir to print the path your copy uses. Yarn 1 doesn't need ~/.yarn at all unless you point its global prefix there: the yarn global docs show yarn config set prefix ~/.yarn, which puts links to your global tools in ~/.yarn/bin. The global packages themselves default to ~/.config/yarn/global.
Yarn 2 and later (Berry) uses ~/.yarn/berry as its global folder. The Yarn configuration reference says enableGlobalCache is on by default, so the zip archive of every package your projects install goes into a cache folder inside ~/.yarn/berry, shared by all projects. A project that turns the global cache off keeps its archives in its own .yarn/cache folder instead.
What happens if you delete it
Package archives come back on the next install. Yarn downloads whatever a project needs, which costs time and bandwidth and fails if you are offline. Nothing personal lives in a Yarn cache: your code, lockfiles and package.json files sit in the projects themselves.
Two things make blind deletion a poor idea:
- Plug'n'Play projects point straight at the cache. Yarn's Plug'n'Play docs explain that the loader references packages by their cache path. Clear the global cache and those projects can't start until you run
yarn installin each one. ~/.yarn/binmay hold your global tools. If you set Yarn 1's prefix there, deleting the folder removes every command you installed withyarn global add. You would have to install them again.
How to check its size safely
This command only reads. It prints the size of whichever of the three locations exist and stays quiet about the rest:
du -sh ~/.yarn ~/Library/Caches/Yarn ~/.cache/yarn 2>/dev/null
To see what sits inside the Yarn 2+ global folder:
du -sh ~/.yarn/berry/* 2>/dev/null | sort -h
In Finder, choose Go > Go to Folder, type ~/.yarn and press Return. Folders whose names start with a dot are hidden, so this is the easiest way in. Select the folder and choose File > Get Info to see its size.
On the macOS 15.5 Mac we checked this on, none of these folders existed, because Yarn had never been installed there. If you only use npm or pnpm, expect the same.
The safest way to get the space back
Use Yarn's own commands in Terminal.
Yarn 1:
- Run
yarn cache dirto confirm where the cache is. - Run
yarn cache clean. The Yarn 1 cache docs say it clears the global cache, which fills again the next time you runyarnoryarn install. Add a package name to clear just that package.
Yarn 2 and later, from inside a project that uses it:
- Run
yarn cache clean --mirror. The cache clean docs say this removes the archives stored in~/.yarn. Plainyarn cache cleanonly removes the current project's local archives, and--alldoes both. - Run
yarn installin each project you still work on, so Plug'n'Play projects have their packages again.
If you would rather clear a Yarn 1 cache folder by hand, quit anything that is running Yarn, then move the folder to the Bin:
trash ~/Library/Caches/Yarn
The trash command comes with macOS 14 Sonoma and later. You can put the folder back from the Bin until you empty it.
Warning: rm -rf ~/.yarn deletes the whole folder at once, skipping the Bin, including any global tools in ~/.yarn/bin and Yarn 2+'s global files. Use the cache commands instead.
What never to touch
~/.yarn/binif your global tools live there.yarn global bintells you where Yarn 1 puts them.- A project's own
.yarnfolder, especially.yarn/releasesand.yarn/plugins, which many teams commit to git. Those are part of the project, not a cache. yarn.lockand.pnp.cjsin your projects. Remove them and installs stop being repeatable.- Any cache while an install is running. Let it finish first.
If Yarn isn't your main package manager, the pages on the npm cache and ~/Library/pnpm cover the others, and our guide to deleting node_modules safely covers the project side.
How Headroom helps
Headroom's Clean scan lists the Yarn 1 cache, in ~/Library/Caches/Yarn or ~/.cache/yarn, under Developer caches with its size and a plain note: Yarn downloads packages again when needed. It is ticked by default and deleted for good when you clean, because it rebuilds. Headroom doesn't clean ~/.yarn or Yarn 2+'s global cache, so use yarn cache clean --mirror for those. The scan is free, and the $19 one-time licence clears what you tick on up to three Macs. See what the cleaner covers or download Headroom.
Questions
Where is the Yarn cache on a Mac?
Yarn 1 usually keeps it in ~/Library/Caches/Yarn, and yarn cache dir prints the exact path. Yarn 2 and later keep a global cache inside ~/.yarn/berry by default.
Is it safe to run yarn cache clean?
Yes. It removes downloaded package archives, which Yarn fetches again on the next install. Projects that use Plug'n'Play need a yarn install afterwards before they run.
Can I delete the whole ~/.yarn folder?
Not blindly. It can hold links to your global tools in ~/.yarn/bin as well as Yarn 2+'s global files. Use yarn cache clean --mirror to clear the cache instead.
Will clearing the Yarn cache break my projects?
Projects installed into node_modules keep working. Plug'n'Play projects point straight at the cache, so run yarn install in each one to fetch their packages again.