Quick answer
# Yarn 1. Clears the global cache. yarn cache dir prints the folder.
yarn cache clean
du -sh "$(yarn cache dir)"
# Yarn 2 and later. Clears this project's cache.
yarn cache clean
yarn cache clean --mirror # global cache only
yarn cache clean --all # global cache and this project's cache
du -sh "$(yarn config get cacheFolder)"
Check yarn --version first. yarn cache dir is Yarn 1 only. On Yarn 2 and later, measure yarn config get cacheFolder.
Which Yarn you have
yarn --version
A 1.x version is Yarn 1 (classic). Yarn 2, 3, and 4 are Berry.
yarn cache clean on Yarn 1
yarn cache clean clears the global cache. Pass package names to clear only those. yarn cache list --pattern filters the list by package name:
yarn cache list --pattern left-pad
yarn cache clean left-pad
yarn cache dir prints the folder, including v6 on Yarn 1.22.22. yarn config get cacheFolder printed undefined on that release. Use yarn cache dir.
yarn cache clean on Yarn 2 and later
yarn cache clean removes the local cache files for the current project. yarn cache clear is an alias. Yarn 4.18.1 accepts both.
| Command | What it removes |
|---|---|
yarn cache clean | Local cache files for the current project |
yarn cache clean --mirror | Global cache files, instead of the local cache |
yarn cache clean --all | Both the global cache and the current project's local cache |
enableGlobalCache defaults to true, so yarn config get cacheFolder printed ~/.yarn/berry/cache on Yarn 4.18.1. Set it to false and the folder is ./.yarn/cache. yarn cache dir is not a Berry command.
Where the Yarn cache is on Mac and Linux
Confirm with yarn cache dir on Yarn 1, or yarn config get cacheFolder on Yarn 2 and later.
| Yarn 1.22.22 | Yarn 4.18.1 | |
|---|---|---|
| macOS | ~/Library/Caches/Yarn/v6 | ~/.yarn/berry/cache |
| Linux | ~/.cache/yarn/v6 | ~/.yarn/berry/cache |
| If an XDG variable is set | $XDG_CACHE_HOME/yarn/v6 | $XDG_DATA_HOME/yarn/berry/cache |
Linux cells are the paths those commands printed. The macOS Yarn 1 cell is the Yarn 1.22.22 default. Yarn 4 uses that global folder on macOS and Linux unless XDG_DATA_HOME is set. XDG_CACHE_HOME moves only Yarn 1. cache-folder, --cache-folder, and YARN_CACHE_FOLDER move Yarn 1 too.
Is it safe to clear the Yarn cache?
The next yarn install downloads the archives again, and node_modules stays. Zero-Installs is the exception. The project commits the cache, usually .yarn/cache with enableGlobalCache set to false. yarn cache clean deletes those files. Yarn says to avoid cache cleaning in that case.
"Cache cleaning is currently disabled"
Yarn 2 and later refuse the command when enableCacheClean is false. The default is true. On Yarn 4.18.1 it stopped and told you to set enableCacheClean: true. Add that line to the project's .yarnrc.yml, then run the clean again:
enableCacheClean: true
yarn cache clear hits the same check.
Not node_modules
Clearing the Yarn cache does not remove project node_modules folders. If those are the gigabytes you are looking at, read can I delete node_modules?
The other package managers: how to clear npm cache and how to clear pnpm cache.
FAQ
- Where is the Yarn cache on Mac?
- On Yarn 1, run yarn cache dir. The Yarn 1.22.22 macOS default is ~/Library/Caches/Yarn/v6, unless cache-folder, --cache-folder, or YARN_CACHE_FOLDER moves it. On Yarn 2 and later, run yarn config get cacheFolder. The default is ~/.yarn/berry/cache unless XDG_DATA_HOME is set.
- Where is the Yarn cache on Linux?
- On Yarn 1.22.22, yarn cache dir printed ~/.cache/yarn/v6, or $XDG_CACHE_HOME/yarn/v6 when that variable is set. On Yarn 4.18.1, yarn config get cacheFolder printed ~/.yarn/berry/cache, or $XDG_DATA_HOME/yarn/berry/cache when that variable is set. If enableGlobalCache is false, the folder is the project's .yarn/cache.
- Is it safe to clear the Yarn cache?
- Yes for a normal install. Packages download again on the next yarn install, and node_modules is not removed. Skip it for Zero-Installs. Yarn says cache cleaning should be avoided then, because the command deletes the committed archives.
- How do I clear the Yarn cache for one package?
- On Yarn 1, run yarn cache clean and the package name. yarn cache list --pattern filters the list. Yarn 2 and later do not take a package name. Use yarn cache clean, --mirror, or --all.
- Does yarn cache clean delete node_modules?
- No. yarn cache clean clears the download cache. It does not remove a project's node_modules folder. Packages download again on the next install.
Scan it with DevCleaner
DevCleaner shows the Yarn 1 cache at ~/Library/Caches/Yarn and the Berry cache at ~/.yarn/berry/cache and ~/.yarn/cache, with the size before you remove them. The Yarn 1 cache is selected with other Safe items. The Berry cache is not selected until you choose it. On macOS 1.17.0, those folders follow Settings → General → Deletion, which defaults to By risk: Safe items are deleted permanently, and Warning and Danger items move to the Trash. Always move to Trash and Always delete permanently are the other choices. The Berry command runs yarn cache clean --all and does not use that setting.
DevCleaner for Linux 1.1.1 lists Yarn Cache at ~/.cache/yarn and ~/.yarn/berry/cache. XDG_CACHE_HOME changes the first path. The row is selected with other Safe items, and cleanup moves the files to the Trash unless you turn that preference off. It does not scan ~/.yarn/cache or a Berry cache moved by XDG_DATA_HOME.
References and scope
Reviewed October 26, 2026 on Yarn 1.22.22 (npm i -g yarn) and Yarn 4.18.1 (corepack). The Linux paths are that command output. The macOS Yarn 1 path is the default in that Yarn 1.22.22 release. Run yarn cache dir or yarn config get cacheFolder before you delete anything.
