# Is it safe to delete Yarn’s cache?

Is it safe to delete? · Package caches · Updated 21 November 2026. By Mohit Nippanikar, who makes SiftMac.

## The short answer

- **Yes**, with one exception. The global caches hold packages Yarn already downloaded. A project’s own `.yarn/cache` folder may be committed to Git on purpose, so check before deleting that one.
- **What it costs you:** the next `yarn install` downloads 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 `enableGlobalCache` is 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 clean` clears the global cache. Name packages to clear only those, for example `yarn cache clean left-pad`.
- **Yarn 2+:** inside a project, `yarn cache clean --mirror` removes the global cache files in `~/.yarn`, plain `yarn cache clean` removes that project’s local cache files, and `yarn cache clean --all` removes 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_modules` hold 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 install` in each, since `.pnp.cjs` points at the cache you emptied.
- `yarn.lock` still decides the versions, so the reinstall gives you the same packages.
- If you emptied a committed `.yarn/cache` by mistake, `git restore .yarn/cache` brings 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: https://siftmac.com/SiftMac.dmg (scanning is free, and so is the first 2 GB of cleaning).

## Sources

- [Yarn Classic: yarn cache](https://classic.yarnpkg.com/en/docs/cli/cache)
- [Yarn: yarn cache clean](https://yarnpkg.com/cli/cache/clean)
- [Yarn: .yarnrc.yml settings (enableGlobalCache, globalFolder, nodeLinker)](https://yarnpkg.com/configuration/yarnrc)
- [Yarn Classic source: the cache folder on macOS](https://github.com/yarnpkg/yarn/blob/master/src/util/user-dirs.js)

## Related

- [Is it safe to delete ~/.npm, npm’s cache?](https://siftmac.com/safe-to-delete/npm-cache)
- [Is it safe to delete pnpm’s store?](https://siftmac.com/safe-to-delete/pnpm-store)
- [Is it safe to delete node_modules?](https://siftmac.com/safe-to-delete/node-modules)
- [Is it safe to delete ~/Library/Caches on a Mac?](https://siftmac.com/safe-to-delete/library-caches)
- [Xcode DerivedData, node_modules and Docker: what’s safe to delete on a developer’s Mac](https://siftmac.com/guides/developer-files-on-mac)

Canonical: https://siftmac.com/safe-to-delete/yarn-cache
