Is it safe to delete ~/.pub-cache?
- Yes. It’s pub’s system cache of packages downloaded for your Dart and Flutter projects. Clearing it also removes tools you activated with
dart pub global activate, so note those first. - What it costs you: each project needs
flutter pub get(ordart pub get) again before it builds. - Does it come back? Yes, package by package, as projects fetch them.
- SiftMac’s verdict: Rebuilds
1. What’s in ~/.pub-cache
When a project runs pub get, pub downloads its dependencies into one system cache shared by every project, and each project refers to the packages there. Inside you’ll find:
hosted: packages from pub.dev (inhosted/pub.dev) and any other package server, one folder per package version.git: packages that come from Git repositories, if your projects use any.bin: launch scripts for command-line tools you activated globally.- A few small bookkeeping files and folders.
The Flutter SDK keeps its own cache of engine and tool files inside the SDK folder, filled by flutter precache and Flutter itself. That one belongs to Flutter, not to pub, and isn’t part of this folder.
2. Where it is
~/.pub-cache
That’s $HOME/.pub-cache on macOS. Setting PUB_CACHE puts it somewhere else, for example on a bigger drive.
3. How big it gets
Every version of every package a project fetched stays, so it grows with the number of projects and upgrades over time rather than with what you use today:
du -sh ~/.pub-cache
du -sh ~/.pub-cache/hosted/*
4. How to clear it
- List your global tools so you can activate them again later.
- Stop running apps and IDE builds.
- Clear the cache. Pub asks first, warning that everything inside will go and that you’ll have to run
pub getagain in each project;--forceskips the question.
dart pub global list
flutter pub cache clean
flutter pub cache clean and dart pub cache clean do the same thing, since flutter pub runs Dart’s pub. dart pub cache repair is different: it reinstalls every package in the cache and frees nothing.
Build folders in projects
Each Flutter project also has build and .dart_tool folders. flutter clean deletes both, and the next build makes them again:
cd ~/Projects/my_app
flutter clean
5. What happens afterwards
- Projects can’t build or be analysed until
flutter pub gethas run in each one. pubspec.lockkeeps every package at the same version, so the fetch gives you what you had.- Globally activated tools stop working until you run
dart pub global activate <package>again. - The Flutter SDK, your simulators and emulators aren’t affected.
Questions
Can I delete ~/.pub-cache in Finder?
Yes, with nothing running; that’s what pub cache clean does for you. Dart’s docs say that with an SDK too old to have the clean command, you delete the PUB_CACHE folder by hand.
Will clearing the pub cache delete my Flutter SDK?
No. The SDK and its own cache live in the folder where you installed Flutter. Only downloaded packages and global tools go.
What does flutter clean delete?
Only the project’s build and .dart_tool folders. It leaves ~/.pub-cache alone, and the next build regenerates both.
Can I move the pub cache to an external drive?
Yes: set PUB_CACHE to the new folder in your shell profile, then run flutter pub get in each project so it refers to packages in the new place.
How SiftMac handles it. SiftMac doesn’t clear ~/.pub-cache. Under Developer files it lists build and .dart_tool folders next to a pubspec.yaml, in projects you haven’t changed for 1, 3 or 6 months, the same folders flutter clean removes, and it leaves the Flutter SDK’s own folders alone.
Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works