How to clear the Yarn cache
Yarn 1 (classic) keeps one global cache. Yarn 2+ (Berry) keeps a global mirror and, depending on settings, a per-project .yarn/cache. Same command name, different folders, so check yarn --version first.
Yarn 1 (classic)
yarn cache dir yarn cache clean # everything yarn cache clean lodash # one package
- macOS:
~/Library/Caches/Yarn - Linux:
~/.cache/yarn - Windows:
%LOCALAPPDATA%\Yarn\Cache
Yarn 2+ (Berry)
yarn cache clean # this project's cache yarn cache clean --mirror # the global mirror yarn cache clean --all # both
The global mirror lives at ~/.yarn/berry/cache on macOS and Linux (%USERPROFILE%\.yarn\berry\cache on Windows).
.yarn/cache for zero-installs, cleaning it shows up as deleted files in git. Don’t commit that change.Measure with devdisk
devdisk is a free, read-only scanner. It lists the Yarn 1 cache under Safe to regenerate with yarn cache clean. It never deletes anything; it only shows sizes and writes a cleanup script you read and run yourself. The Berry mirror is not scanned yet; check it with du -sh ~/.yarn/berry/cache.
curl -fsSLO https://disk.sadana.app/devdisk.py && python3 devdisk.py
iwr https://disk.sadana.app/devdisk.py -OutFile devdisk.py; py devdisk.py
Want one-click cleanup?
A planned devdisk desktop app for Mac and Windows: live treemap, cleanup that moves files to the Trash, scheduled scans. One email when it launches, with an early-supporter price. Your address is used only for that, and every email has an unsubscribe link.
FAQ
Is clearing the Yarn cache safe?
Yes. Packages are downloaded again on the next install. Avoid running it while an install is in progress.
Why is my cache still big after yarn cache clean?
You may be on Berry, where the global mirror needs yarn cache clean --mirror, or have several Yarn versions with separate caches.
Does devdisk clear the cache for me?
No. It is read-only and only suggests the command.