Is it safe to delete Yarn’s cache?
- Yes, with one exception. The global caches hold packages Yarn already downloaded. A project’s own
.yarn/cachefolder may be committed to Git on purpose, so check before deleting that one. - What it costs you: the next
yarn installdownloads again, and Yarn 2+ projects using Plug’n’Play can’t run until it has. - Does it come back? Yes, with every install.
- SiftMac’s verdict: Rebuilds
1. Two Yarns, two caches
Yarn comes in two lines that store packages differently. Run yarn --version inside a project to see which one it uses: 1.x is Yarn Classic, and anything from 2 up is modern Yarn, often called Berry.
- Yarn Classic (1.x) keeps every package it has installed in one global cache and copies them into each project’s
node_modules. - Yarn 2 and later keep packages as archives. By default they go to a global folder shared by all projects, because
enableGlobalCacheis on. With it off, they go to the project’s own.yarn/cache, which some teams commit to Git so a fresh checkout can run without installing; Yarn calls that Zero-Installs.
Modern Yarn’s default linker is Plug’n’Play. Instead of a node_modules folder it writes a .pnp.cjs loader that refers to packages by their path in the cache. That makes the cache part of how a project runs, not only a download shortcut.
2. Where each one lives
~/Library/Caches/Yarn # Yarn Classic
~/.yarn/berry # Yarn 2+ global folder, cache inside
<project>/.yarn/cache # Yarn 2+ with the global cache off
Yarn Classic picks ~/Library/Caches/Yarn on a Mac unless XDG_CACHE_HOME, YARN_CACHE_FOLDER or its cache-folder setting says otherwise; yarn cache dir prints the exact folder, version subfolder included. For Yarn 2+, the globalFolder setting decides, and it’s ~/.yarn/berry unless changed.
3. How big it gets
Each cache keeps the packages your projects asked for, version by version, including projects you deleted long ago. A Mac that has used both lines of Yarn can have both folders. Check them together:
du -sh ~/Library/Caches/Yarn ~/.yarn/berry 2>/dev/null
yarn cache dir
4. How to clear it
Use the Yarn that owns the cache:
- Yarn Classic:
yarn cache cleanclears the global cache. Name packages to clear only those, for exampleyarn cache clean left-pad. - Yarn 2+: inside a project,
yarn cache clean --mirrorremoves the global cache files in~/.yarn, plainyarn cache cleanremoves that project’s local cache files, andyarn cache clean --allremoves both.
yarn cache clean # Yarn 1: the global cache
yarn cache clean --mirror # Yarn 2+: the global cache
Before clearing a project’s .yarn/cache, run git status there or look in .gitignore. If Git tracks the folder, it’s part of the project rather than a leftover, and deleting it shows up as a long list of deleted files.
5. What changes afterwards
- Yarn Classic projects keep running: their
node_moduleshold full copies of the packages. The next install downloads what’s missing. - Plug’n’Play projects can’t find their packages until you run
yarn installin each, since.pnp.cjspoints at the cache you emptied. yarn.lockstill decides the versions, so the reinstall gives you the same packages.- If you emptied a committed
.yarn/cacheby mistake,git restore .yarn/cachebrings it back.
Questions
Which Yarn cache is the big one on my Mac?
Measure both with du -sh ~/Library/Caches/Yarn ~/.yarn/berry. Each version of Yarn only knows and clears its own, so a Mac that has used both may need both commands.
Is it safe to delete .yarn/cache inside a project?
Only if Git doesn’t track it. Teams using Zero-Installs commit that folder so the project runs straight after a checkout; if you delete it and commit, everyone else loses it too.
Will yarn cache clean delete node_modules?
No. It only touches the cache. A project’s node_modules, if it has one, stays until you delete it yourself.
Can I move Yarn’s cache to another disk?
Yes. For Yarn Classic, run yarn config set cache-folder <path> or set YARN_CACHE_FOLDER. For Yarn 2+, set globalFolder in .yarnrc.yml.
How SiftMac handles it. Its App caches category lists ~/Library/Caches/Yarn as Yarn packages with a Rebuilds verdict, ticked by default like other caches, and clears what’s inside while keeping the folder. Modern Yarn’s ~/.yarn folder and projects’ .yarn/cache aren’t cleared by SiftMac; yarn cache clean --mirror handles the global one.
Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works