A 512 GB MacBook running two Next.js apps and a Yarn Berry monorepo often sits at 34 GB of Yarn cache before anyone notices. Half of that lives in ~/Library/Caches/Yarn/v6/ from years of Classic installs, the other half is duplicated across per-project .yarn/cache/ folders that Berry writes on every clone. The same shape of surprise is in a developer's writeup of freeing 200 GB on a full disk: "After the initial Docker/cache cleanup freed 150GB, going back and asking 'what else?' found another 75GB." Yarn cache is one of those follow-up finds.
Where is the Yarn cache actually located on Mac?
There are three answers depending on which Yarn you run. The active location for the current shell is always this command.
yarn cache dir
That prints the directory Yarn will read from and write to for install operations. On Mac the value depends on the Yarn version.
| Yarn version | Default cache path | Scope | Auto-expires? |
|---|---|---|---|
| Yarn Classic v1 | ~/Library/Caches/Yarn/v6/ |
Global, all projects | No |
| Yarn Berry v2 to v4 | <project>/.yarn/cache/ |
Per project | No |
Yarn Berry with enableGlobalCache: true |
~/.yarn/berry/cache/ |
Global, all Berry projects | No |
| Corepack-managed Yarn | Same as the version Corepack resolves | Depends on version | No |
The two locations to know cold. ~/Library/Caches/Yarn/v6/ is where Yarn Classic hides its footprint under the same ~/Library/Caches tree that macOS folds into the gray System Data bar. <project>/.yarn/cache/ is the Berry per-project directory that ships alongside .pnp.cjs when you clone the repo.
If you have both v1 and Berry installed on the same Mac (very common on machines that survived the migration), the total Yarn cache mac footprint is ~/Library/Caches/Yarn/v6/ plus every .yarn/cache/ under every checkout plus optionally ~/.yarn/berry/cache/. That is three separate accounts to audit.
How do I measure Yarn cache size honestly on Mac?
A read-only audit script. Nothing gets deleted. Paste this into Terminal from any directory.
# Read-only Yarn cache audit on Mac
{
printf "\n=== Yarn Classic v1 ===\n"
du -sh ~/Library/Caches/Yarn 2>/dev/null
du -sh ~/Library/Caches/Yarn/v6 2>/dev/null
printf "\n=== Yarn Berry global (if enableGlobalCache) ===\n"
du -sh ~/.yarn 2>/dev/null
du -sh ~/.yarn/berry/cache 2>/dev/null
printf "\n=== Per-project Berry caches under $HOME ===\n"
find "$HOME" -type d -name ".yarn" -not -path "*/node_modules/*" 2>/dev/null \
| while read -r d; do
if [ -d "$d/cache" ]; then
du -sh "$d/cache" 2>/dev/null
fi
done | sort -hr | head -20
printf "\n=== Active dir for this shell ===\n"
command -v yarn >/dev/null && yarn cache dir
printf "\n=== Free disk ===\n"
df -h / | awk 'NR==2 {print $4 " available on " $1}'
}
The find pass is the one that tells the truth. On a Mac with three Berry monorepos the Classic cache might read 8 GB while the per-project caches quietly sum to 22 GB. The Storage bar in System Settings never surfaces either of them separately.
For the cross-cache picture beyond Yarn, find-all-node-modules-mac is the per-project node_modules sweep and pnpm-store-cleanup is the same audit shape for pnpm.
How do I run yarn cache clean on Yarn Classic v1?
yarn cache clean on Yarn Classic v1 removes the entire cache directory contents. It never touches node_modules. It never invalidates yarn.lock. Every project on the machine keeps working. The only cost is that the next yarn install in each project does a slower cold pull from the registry.
# Before-and-after size check
du -sh ~/Library/Caches/Yarn/v6
# Wipe every package in the Classic cache
yarn cache clean
# Or target a single package
yarn cache clean react
# Confirm
du -sh ~/Library/Caches/Yarn/v6 2>/dev/null || echo "cache empty"
If you want the rollback safety of Finder Trash instead of a hard delete, move the cache directory to ~/.Trash with a timestamp and let it sit for a week. This is the pattern CleanMyDev uses across every cache target it ships with.
# Move-to-Trash style: keeps a 7-day rollback window
STAMP="$(date +%Y%m%d-%H%M%S)"
mv ~/Library/Caches/Yarn "$HOME/.Trash/yarn-classic-cache-$STAMP"
That command survives Time Machine, survives an emptied Trash if you catch it within seven days on APFS with the default snapshot cadence, and never asks for sudo. The skeptical-dev safety argument behind this default is at why-cleanmydev-shows-receipts.
How do I clean the Yarn Berry cache?
Yarn Berry is the harder half. There is no equivalent to yarn cache clean --all for the global picture, because Berry caches are per project by default. The commands run inside the project directory.
# Cleans zip archives no longer referenced by yarn.lock in this project
yarn cache clean
# Nuclear per-project reset: reclaims the full .yarn/cache/
rm -rf .yarn/cache && yarn install
The nuclear reset is safe for the project you run it in, but doing it across ten checkouts by hand is tedious and error-prone. The honest audit shape is the read-only find above, sort by size, and either move each project's .yarn/cache/ to a timestamped Trash directory or flip on the global cache so future clones share one directory.
# .yarnrc.yml at the project root or ~/.yarnrc.yml globally
enableGlobalCache: true
With that flipped, new installs read from and write to ~/.yarn/berry/cache/ instead of the project directory. You still need to migrate existing projects by deleting their .yarn/cache/ and running yarn install again, but from that point forward the per-project footprint drops to zero for Berry.
For the parallel move on the pnpm side see pnpm-store-cleanup, and for the Bun install cache see bun-cache-location-mac.
What is the safe Yarn cache cleanup order on a low-disk day?
Order matters when the Mac is under 5 GB free. Each step is reversible from Trash for seven days, and each step reclaims a known amount.
- Run the read-only audit above. Know the numbers before you touch anything.
- Quit any editor that has a Yarn project open, so no file-watcher is holding a lock on
.yarn/cache/. - Move
~/Library/Caches/Yarn/to a timestamped Trash directory. Reclaim is immediate, usually 10 to 40 GB. - For each Berry project sorted by cache size, move
<project>/.yarn/cache/to Trash with the project name in the stamp. Reclaim per project is 200 MB to 4 GB. - If you use Corepack, run
corepack cache cleanto wipe the Corepack-managed Yarn binaries you no longer use. - Run the audit script again. If it still shows non-trivial Yarn size, check
findfor.yarndirectories outside$HOME, sometimes SDK clones land under/opt. - Wait seven days. If nothing regressed, empty Trash.
This is the same safety floor playwright-cache-cleanup uses for browser bundles and it is the floor CleanMyDev uses across every JS cache, AI cache, and Xcode cache target it ships with.
Can I move the Yarn cache to an external SSD?
Yes, and on a 256 GB MacBook this is often the right call. The Yarn cache is exactly the kind of data that is large, regenerable, and not latency-sensitive enough to need internal SSD.
For Yarn Classic v1 set the cache-folder config.
yarn config set cache-folder /Volumes/Externals/yarn-cache
yarn cache dir
For Yarn Berry with global cache enabled, set globalFolder in ~/.yarnrc.yml.
enableGlobalCache: true
globalFolder: /Volumes/Externals/yarn-berry
After either change, run yarn cache dir again to confirm the new Yarn cache location on Mac, then run any yarn install to populate it. Once you are confident the new path works, move the old cache directory to Trash with the timestamped pattern above.
What does CleanMyDev do for Yarn cache that yarn cache clean does not?
yarn cache clean is one button per project or per version. It cannot see across Yarn Classic, Yarn Berry per-project caches, Corepack binaries, and every sibling install cache on the same Mac. CleanMyDev shows the full picture before you click anything. It maps Yarn Classic, Yarn Berry per-project, ~/.yarn/berry/cache/, npm ~/.npm/_cacache, pnpm ~/Library/pnpm/store/v3, Bun ~/.bun/install/cache, Playwright browser binaries, and every per-project node_modules on the same screen. Per-row size, last-modified date, risk label. You tick the rows you want to reclaim, the cumulative number updates live, and the deletions land in Finder Trash with a timestamp.
If you have been chasing the System Data gray bar for a week and you are tired of writing one-off shell scripts per tool, grab CleanMyDev for $9.99 lifetime on the pricing page. One purchase, no subscription, no telemetry, covers Yarn cache and every other JS, AI, and Xcode cache discussed across this blog.
Related reading
- npm-cache-location-mac for the npm side of the same audit.
- pnpm-store-cleanup for the pnpm store equivalent.
- bun-cache-location-mac for Bun install cache with the same Trash-first floor.