Can I Delete .pub-cache? Yes, and Flutter Will Rebuild It

Yes, it's safe to deleteDiskmack safety tier: Safe to clean
~/.pub-cache

Yes, you can delete ~/.pub-cache. It is a cache of downloaded Dart and Flutter packages, and it rebuilds itself: the next time you run flutter pub get in a project, everything that project needs is downloaded again from pub.dev. The only real cost is time and bandwidth, plus one caveat if you use dart pub global tools, covered below.

What it is

.pub-cache is the shared package store for Dart and Flutter, kept at ~/.pub-cache in your home folder. When you run flutter pub get or dart pub get, the pub package manager downloads every dependency listed in your project's pubspec.yaml and stores it here. Projects do not each get their own copy the way Node projects do with node_modules. Every Flutter and Dart project on your Mac resolves its packages out of this one folder.

It grows because pub keeps every version it has ever downloaded. Upgrade a package and the old version stays behind. Switch between Flutter SDK releases and each one pins different versions of the core packages, so you accumulate parallel sets of nearly identical code. Git dependencies are stored as full repository clones under ~/.pub-cache/git, and command line tools installed with dart pub global activate live under global_packages. On a Mac that has seen a couple of years of Flutter work, the folder often reaches several gigabytes.

Is it safe to delete?

Deleting ~/.pub-cache is safe. It contains nothing unique: no project code, no settings, no signing keys. Everything in it came from pub.dev or a git remote and can be fetched again. After you delete it, the next flutter pub get in each project re-downloads that project's dependencies, pinned to the exact versions in its pubspec.lock, so your builds come back identical.

Two things to know first. Your next pub get in every project will be slower, since packages have to come over the network again. And if you have installed tools with dart pub global activate (fvm, melos, very_good_cli and the like), those live inside the cache and disappear with it, so plan to re-activate them afterward. Diskmack identifies ~/.pub-cache automatically and cleans it the safe way.

How to check its size

In Finder: In Finder, choose Go > Go to Folder (Cmd-Shift-G), type ~/.pub-cache and press Return. The folder is normally hidden because its name starts with a dot, but Go to Folder opens it anyway. Once inside, press Cmd-I with nothing selected and Finder shows Get Info for the folder itself. Give it a moment: the cache is thousands of small files, so the size takes a few seconds to add up.

In Terminal:

du -sh ~/.pub-cache

How to clean it

  1. Quit your IDE and stop any running flutter or dart commands so nothing is writing to the cache.
  2. In Finder, choose Go > Go to Folder (Cmd-Shift-G), type ~ and press Return to open your home folder.
  3. Press Cmd-Shift-. (the period key) to reveal hidden files, drag .pub-cache to the Trash, then empty the Trash to reclaim the space. Press Cmd-Shift-. again to re-hide the rest.
  4. Open Terminal, cd into each Flutter project you are actively working on, and run flutter pub get to re-download its packages.
  5. If you had global tools installed, re-run dart pub global activate for each one (dart pub global activate fvm, for example).

Dart also has a command for this: dart pub cache clean empties the cache from Terminal and asks for confirmation first. It has shipped with every SDK since Dart 2.14 in 2021, so unless your toolchain is ancient you have it. If your problem is corrupted packages rather than disk space, dart pub cache repair re-downloads everything in place instead of deleting it.

Will it come back?

Yes, and fairly quickly if you work in Flutter every day. The first flutter pub get after cleaning rebuilds the cache with whatever your current projects need, which usually lands somewhere between a few hundred megabytes and a couple of gigabytes. From there it creeps upward again as you upgrade packages and Flutter versions, because pub never evicts old versions on its own. Treat clearing it as something you do once or twice a year, or after retiring an old Flutter SDK, not as a way to keep the folder permanently small.

Common questions

Will deleting .pub-cache break my Flutter projects?

No. Projects only reference the cache; nothing of theirs is stored in it. The next flutter pub get restores the exact versions listed in each project's pubspec.lock, so the code you build against is identical. The first build after cleaning just takes longer while packages download.

Is there a command instead of deleting the folder by hand?

Yes. dart pub cache clean empties the whole cache and prompts for confirmation before it deletes anything. flutter pub cache clean does the same thing, since the Flutter tool just forwards it to dart pub.

Can I delete just part of it?

Yes, with a catch. The hosted folder inside ~/.pub-cache holds the packages downloaded from pub.dev and is usually most of the size, so deleting just that recovers nearly everything. The catch: tools installed with dart pub global activate load their code out of hosted too, so one of them can stop working later, typically right after a Dart SDK update. If that happens, re-run dart pub global activate for that tool.

Why is my .pub-cache so large?

Pub never removes old package versions. Every upgrade adds a new copy next to the previous one, and every Flutter SDK you have used pins its own set of core package versions. Git dependencies also sit there as full repository clones. A couple of years of normal Flutter work can add up to several gigabytes.

Related folders