Sub topic 11
Developer and package manager caches
This chapter assumes you have read the earlier chapters on caches and on ~/Library/Caches. It also assumes you can run simple commands in Terminal. If you do not develop software or use Homebrew, you can skim this chapter.
Why developer caches get large
Developer tools store downloads so they can reuse them. Package managers keep installer files and old versions. Build tools keep compiled output. Over months this adds up to many gigabytes. The Storage settings pane often shows it as "Developer", or inside "System Data" or "Documents".
These caches follow the same rule as other caches. They can be rebuilt, but rebuilding costs time and network traffic. Clearing them is safe in most cases. The price is a slower next build or a fresh download.
Preview before you delete
Start by measuring. The commands below only read sizes or preview changes.
du -sh ~/Library/CachesFor Homebrew, ask what cleanup would remove. The -n flag means dry run, so nothing is deleted.
brew cleanup -nThe output lists outdated downloads and old versions of installed packages. If the list looks right, run the real command.
brew cleanupHomebrew keeps the current version of each package. Cleanup removes only older versions and stale downloads.
Common cache locations
These paths are common defaults. Check that a folder exists before you measure it, because not every Mac has every tool.
| Tool | Typical location | Rebuilt by |
|---|---|---|
| Homebrew downloads | `~/Library/Caches/Homebrew` | `brew install` |
| npm | `~/.npm` | `npm install` |
| pip | `~/Library/Caches/pip` | `pip install` |
| Xcode build output | `~/Library/Developer/Xcode/DerivedData` | Building the project |
| Xcode simulators | `~/Library/Developer/CoreSimulator` | Xcode downloads runtimes again |
Use du to see which ones matter on your machine.
du -sh ~/.npm ~/Library/Caches/pip ~/Library/Developer/Xcode/DerivedData 2>/dev/nullThe 2>/dev/null part hides errors for folders that do not exist.
Prefer the tool's own cleanup
A tool's cleanup command knows what is safe. Deleting folders by hand can break things the tool still expects to find. Two examples:
- npm:
npm cache verifychecks the cache and removes stale data.npm cache clean --forceempties it. - Xcode: deleting contents of
DerivedDatais a well-known fix for odd build errors. Xcode regenerates it on the next build.
What to leave alone
Not everything under a developer folder is a cache. These items hold real data or configuration:
- Docker images and volumes. Volumes can contain database contents. Use
docker system dfto see usage, and read what a prune command will remove before you run it. - Virtual environments and
node_modulesfolders inside projects. They can be recreated, but only if the project has a lockfile or requirements file. - Configuration files such as
~/.zshrc,~/.gitconfig, and~/.ssh.
Check the result
After cleanup, confirm the change with the same measurements you used before. Compare free space on the data volume.
df -h /System/Volumes/DataThen build one project or install one package. If it works, the cache was rebuildable as expected.
Exercise
You run brew cleanup -n and it lists several old versions of packages. Does that command free any space, and what is the next step?
Show answer
No. The -n flag is a dry run, so it only shows what would be removed. If the list looks right, run brew cleanup to delete those items, then check free space with df -h /System/Volumes/Data.
Exercise
Why is npm cache verify a better first choice than deleting ~/.npm yourself?
Show answer
It is the tool's own command, so it removes only stale data and leaves the cache in a state npm expects. Deleting the folder works too, but it removes everything and forces full re-downloads.