Every package manager keeps a local cache of what it downloads, and most never clean it up on their own. Over a few years of projects, these caches can easily reach tens of gigabytes. The good news is that almost all of them can be safely cleared, because the tools download what they need again.
Before you start: stop running builds, installs and dev servers. Clearing a cache while a tool is using it can cause confusing errors.
See where the space is
This read-only command shows the size of common cache folders:
du -sh ~/Library/Caches/Homebrew ~/.npm ~/Library/pnpm ~/Library/Caches/pip ~/Library/Caches/uv ~/.gradle/caches ~/Library/Caches/CocoaPods ~/.pub-cache ~/.cargo/registry 2>/dev/null
Folders that do not exist are skipped.
Homebrew
Homebrew keeps downloaded bottles and old versions of formulae. Clean them up with:
brew cleanup
To also remove all cached downloads, not just old ones:
brew cleanup --prune=all
Run brew cleanup -n first to see what would be removed without removing it.
npm, Yarn and pnpm
npm cache clean --force
yarn cache clean
pnpm store prune
npm cache verify checks and tidies the cache without clearing everything. pnpm store prune removes packages not referenced by any project, which is safe for a pnpm store shared between projects.
Old node_modules folders
Each JavaScript project has its own node_modules, often hundreds of megabytes. To list them in a folder of projects without deleting anything:
find ~/code -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null
Delete node_modules in projects you are not actively working on. Running npm install brings it back.
Python: pip and uv
pip cache purge
uv cache clean
uv cache prune is a gentler option that removes only unused entries. Virtual environments (.venv folders) in old projects can also be large and can be recreated from your requirements file.
Gradle
Gradle's dependency cache lives in ~/.gradle/caches. Stop any running daemons, then delete it:
./gradlew --stop
rm -rf ~/.gradle/caches
Gradle downloads dependencies again on the next build. Android Studio users can also remove old Android SDK platforms and system images in Settings > Languages & Frameworks > Android SDK, and old emulators in the Device Manager.
CocoaPods
pod cache clean --all
This clears downloaded pods. Your projects' Pods folders and Podfile.lock are not affected.
Dart and Flutter
dart pub cache clean
This removes everything in the pub cache, including globally activated tools, which you will need to activate again. Running flutter pub get in a project fetches its packages again. flutter clean in a project removes its build output.
Rust (Cargo)
Run cargo clean in projects you are not working on to remove their target folders, which are often the largest Rust storage. The registry cache in ~/.cargo/registry can be deleted and will be downloaded again.
Docker
Docker Desktop stores images, containers, volumes and build cache in a single disk image, so its storage does not shrink by deleting files in Finder.
-
See what is using space:
docker system df -
Remove stopped containers, unused networks, dangling images and build cache:
docker system pruneAdd
-ato also remove all images not used by a container. Do not add--volumesunless you are sure: volumes hold persistent data such as local databases. -
In Docker Desktop > Settings > Resources, you can see and limit the disk image size.
Xcode
Xcode's DerivedData, archives, device support files and simulators are covered in our separate guide to clearing Xcode storage.
Frequently asked questions
Is it safe to clear the npm cache?
Yes. npm downloads packages again as needed. Stop any running installs first. Your projects and their node_modules folders are not affected.
Will docker system prune delete my data?
By default it removes stopped containers, unused networks, dangling images and build cache, but not volumes. Volumes, which often hold databases, are only removed if you add --volumes.
Can I delete ~/.gradle/caches?
Yes, after stopping Gradle daemons. Gradle downloads dependencies again on the next build, which takes time and bandwidth.
Want this done for you?
spacerecover finds Homebrew, npm, Gradle, CocoaPods, pip, uv, Swift package and Dart caches, plus Xcode build output and Docker storage, and explains what each one rebuilds. It never runs blanket prune commands, and projects in your code folders are protected.