Sub topic 11
Developer and package manager caches
This chapter assumes you have read the earlier chapters on user caches in ~/Library/Caches and on safe deletion. You should also be comfortable running simple commands in Terminal. If you have never installed Homebrew, Xcode, Docker, or a language toolchain, you can skim this chapter. These tools are the biggest cache producers on most developer Macs, and they often hold tens of gigabytes that the Storage settings pane lumps into "Developer" or "System Data".
Why developer caches are different
The caches from the previous chapter belong to apps. Those apps manage them, and macOS can often reclaim them. Developer caches differ in three ways:
- Tools do not cooperate with macOS. Storage settings does not mark Homebrew downloads or npm packages as purgeable. They stay on disk until you or the tool removes them.
- They live in many places. Some tools use
~/Library/Caches. Others use dotfolders in your home folder such as~/.npmor~/.cargo. Xcode uses~/Library/Developer. - They mix disposable and valuable data. Xcode's
DerivedDatafolder is safe to delete. Xcode'sArchivesfolder holds builds you may not be able to recreate. A Docker volume may hold a database.
The rule is the same one from the safe deletion chapter. A cache holds data the tool can rebuild or re-download. A cache is not a place where the only copy of anything lives. The hard part is knowing which folders are caches.
Measure before you delete
Start by finding out which tools use the most space. This script prints the size of common developer locations. It skips any that do not exist.
#!/bin/bash
# Print the size of common developer cache locations, if present.
paths=(
"$HOME/Library/Caches/Homebrew"
"$HOME/.npm"
"$HOME/Library/Caches/pip"
"$HOME/Library/Caches/Yarn"
"$HOME/Library/pnpm"
"$HOME/.cargo/registry"
"$HOME/go/pkg/mod"
"$HOME/.gradle/caches"
"$HOME/.m2/repository"
"$HOME/Library/Caches/CocoaPods"
"$HOME/Library/Developer/Xcode/DerivedData"
"$HOME/Library/Developer/Xcode/Archives"
"$HOME/Library/Developer/Xcode/iOS DeviceSupport"
"$HOME/Library/Developer/CoreSimulator"
"$HOME/Library/Containers/com.docker.docker"
)
for p in "${paths[@]}"; do
[ -e "$p" ] && du -sh "$p" 2>/dev/null
done | sort -hrSave it as devcache.sh, then run bash devcache.sh. The output lists the largest locations first.
The command from the earlier chapters still gives the overall picture for user-level caches:
du -sh ~/Library/CachesDo not delete based on this list alone. Use each tool's own cleanup command wherever one exists. The tool knows what it still needs, and a plain rm -rf does not.
Homebrew
Homebrew keeps downloaded bottles (prebuilt packages) and old versions of formulae after you upgrade them. Ask Homebrew where its cache is:
brew --cacheOn most Macs this prints a path under ~/Library/Caches/Homebrew. Preview what cleanup would remove before you run it:
brew cleanup -nThe -n flag is short for --dry-run. It lists files and does not delete anything. When the list looks reasonable, run brew cleanup without the flag. By default it removes old versions of installed formulae and downloads older than 120 days.
Two related commands go further:
brew cleanup -salso scrubs the cache of the latest downloads. You free more space, but a reinstall has to download the package again.brew autoremoveremoves dependencies that nothing installed depends on any more. Runbrew autoremove -nfirst to preview, because it can remove a package you installed only as a dependency and later started using directly.
Language package managers
Each package manager has a cache of downloaded packages. Deleting it costs you re-download time and nothing else, because the tool fetches the packages again on the next install. The cache is separate from your project's installed dependencies (such as node_modules), which you can also rebuild but which live in project folders.
| Tool | Find the cache | Clean it |
|---|---|---|
| npm | `npm config get cache` | `npm cache verify`, or `npm cache clean --force` |
| pip | `pip cache dir` | `pip cache purge` |
| Yarn | `yarn cache dir` | `yarn cache clean` |
| pnpm | `pnpm store path` | `pnpm store prune` |
| Go | `go env GOCACHE GOMODCACHE` | `go clean -cache -modcache` |
| CocoaPods | `~/Library/Caches/CocoaPods` | `pod cache clean --all` |
| Cargo | `~/.cargo/registry` and `~/.cargo/git` | Delete the folders, or use the `cargo-cache` tool |
| Gradle | `~/.gradle/caches` | Delete the folder |
| Maven | `~/.m2/repository` | Delete the folder |
Some of these need care.
- npm.
npm cache verifyremoves corrupted and unneeded entries and is the gentler option. npm refusesnpm cache cleanwithout--forcebecause it considers the cache self-healing and rarely needs wiping. - pnpm. The store is shared between projects through hard links.
pnpm store pruneremoves only packages that no project references any more. Deleting the store by hand can break installed projects. - Maven.
~/.m2/repositoryis a local repository as well as a cache. It may hold artifacts you installed yourself withmvn installand cannot download from anywhere. Check before you delete it. - Go.
go clean -modcacheremoves every downloaded module. Builds work again after the next download, but the first build is slow.
Use the "find" column first and read the path. If the tool reports a location outside your home folder, or a path you do not recognize, stop and investigate.
Xcode
Xcode is often the largest single consumer on a developer Mac. Its data lives under ~/Library/Developer, and the folders differ in how safe they are to remove.
| Folder | What it holds | Safe to delete? |
|---|---|---|
| `Xcode/DerivedData` | Build products, indexes, and logs | Yes. Xcode rebuilds it, but the next build is slower. |
| `Xcode/iOS DeviceSupport` | Debug symbols copied from connected devices | Yes. Xcode recreates them when you reconnect a device. |
| `Xcode/Archives` | Archived app builds | Be careful. You need them to symbolicate crash reports for released builds. |
| `CoreSimulator/Devices` | Simulator disk images and app data | Do not delete by hand. Use `simctl`. |
Quit Xcode before you delete DerivedData. For simulators, use the tool that knows about them:
xcrun simctl list devices
xcrun simctl delete unavailableThe first command shows your simulators. The second removes simulators whose runtime is no longer installed, which is the common leftover after an Xcode upgrade. Deleting a simulator also deletes the app data stored inside it. Do this only if you do not need that test data.
Docker
Docker Desktop on a Mac runs Linux in a virtual machine. All images, containers, volumes, and build cache live inside one large disk image file under ~/Library/Containers/com.docker.docker. Finder and du show it as one big file, so you cannot see what is inside it from macOS. Ask Docker:
docker system dfThe output breaks space into images, containers, local volumes, and build cache, and shows how much of each is reclaimable. Then prune in steps, starting with the least risky:
docker builder prune
docker image prune
docker system prunedocker builder pruneremoves build cache.docker image pruneremoves dangling images, meaning untagged leftovers from rebuilds.docker system pruneremoves stopped containers, unused networks, dangling images, and build cache. It does not remove volumes unless you add--volumes.
Avoid --volumes unless you know what each volume contains. A volume is where a local database keeps its data, and pruning it is permanent.
Two surprises are common. First, the disk image file may not shrink after you prune, because it is a sparse file that can stay large. Docker Desktop's settings have a disk usage view and a resize option, so check there. Second, docker system prune asks for confirmation. Read the warning text, because it lists exactly what will go.
A decision path
The diagram summarizes how to treat any cache folder you meet.
Failure modes and gotchas
- Slow first build. After you clear
DerivedData, a Go cache, or a Gradle cache, the next build is slow and may need network access. Do not clear these right before a deadline or while offline. - Offline work. A cleared package cache means a fresh install needs the network. If you rely on cached packages on a plane, keep them.
- Space does not return. Deleted files go to the Trash only if you use Finder. Terminal deletion is immediate. If free space does not change after a Terminal cleanup, a snapshot may still hold the data. The next chapter covers local snapshots.
- Shared tools. Cleaning one cache may affect other projects. pnpm's shared store and Maven's local repository are the usual examples.
- Regrowth. Caches fill up again as you work. Clearing them once helps, but a routine helps more. The last chapter covers one.
Check the result
After cleanup, measure again and compare with the numbers from the start of the chapter:
df -h /System/Volumes/DataFree space may take a short time to update. If a folder you cleaned shows the same size, make sure the tool is not running and check for a second copy of the cache elsewhere, such as an old version of a language runtime with its own folder.
Exercise
You run brew cleanup -n and it lists several old versions of installed formulae. Nothing was deleted. What does this tell you, and what is the next step?
Show answer
The -n flag is a dry run, so it only previews what brew cleanup would remove. If the list looks reasonable, run brew cleanup without -n to delete those files. Afterward, measure the Homebrew cache again, for example with du -sh "$(brew --cache)".
Exercise
A teammate suggests freeing space by deleting ~/Library/Developer/Xcode/Archives and ~/Library/Developer/Xcode/DerivedData. Which folder is safe to delete without worry, and why does the other one need care?
Show answer
DerivedData is safe because it holds build products, indexes, and logs that Xcode recreates (the next build is just slower). Archives holds archived app builds that you may need to symbolicate crash reports for released versions, so deleting it can lose data you cannot regenerate. Back up or check before removing it.
Exercise
You ran docker system prune and the Docker disk image file in ~/Library/Containers/com.docker.docker is still the same size. Name one reason and one place to check.
Show answer
Docker Desktop stores everything in a sparse disk image that does not always shrink after files are deleted inside it. Check docker system df to see what is still in use, and look at Docker Desktop's disk usage and resize settings.