Guide · Developers
How to clear Xcode, npm, Docker and other developer caches on Mac
Xcode, simulators, package managers and Docker all keep copies of what they've built or downloaded, and not all of them clean up after themselves. Here is where each one lives, what's safe to remove, and the exact command to do it.
The short answer
Most developer caches on a Mac are safe to delete, because each tool downloads or rebuilds them when it needs them again. Use the tool's own command where it has one, and leave your source code, .git folders, shipped Archives and signing files alone.
- Delete Xcode's DerivedData in
~/.Library/ Developer/ Xcode/ DerivedData - Remove old simulators with
xcrun simctl delete unavailable. - Delete
node_modulesin projects you aren't working on. - Run
npm cache clean --forceandpnpm store prune. - Run
brew cleanupandbrew autoremove. - Check
docker system df, then rundocker system prune. - Run
go clean -modcache, andcargo cleanin old Rust projects.
Check your sizes first
Before deleting anything, see where the space went. This command measures the usual developer folders in your home folder, skips the ones you don't have, and prints the biggest last:
du -sh ~/Library/Developer/Xcode/DerivedData \
~/Library/Developer/Xcode/Archives \
~/Library/Developer/Xcode/"iOS DeviceSupport" \
~/Library/Developer/CoreSimulator \
~/.npm ~/Library/pnpm ~/.bun/install/cache \
~/.cargo/registry ~/go/pkg/mod ~/.gradle/caches \
~/Library/Caches 2>/dev/null | sort -h
It reads every file, so give it a minute. Then start with the sections for your biggest folders.
Caches come back; your work doesn't. Delete a cache and the tool rebuilds or downloads it again, which costs time on the next build but no data. The exceptions are gathered under What never to delete.
Xcode: DerivedData, Archives and device support
Xcode keeps what it generates under ~/, and Swift packages and CocoaPods add caches of their own.
DerivedData
DerivedData is Xcode's working folder: build products, intermediate files, indexes and logs, in one subfolder for each project or workspace you build.
Where it lives: ~/ by default. To confirm, open Xcode > Settings and click Locations. The Derived Data path is shown there, and the small arrow next to it opens the folder in Finder.
Is it safe to delete? Yes. Xcode rebuilds all of it. Quit Xcode, then move the folder's contents to the Trash, or run:
rm -rf ~/Library/Developer/Xcode/DerivedData
The next build takes longer while Xcode recompiles and re-indexes. To clear only the open project's build files, choose Product > Clean Build Folder (Shift Command K).
Archives
Product > Archive saves an .xcarchive bundle holding the built app and its dSYM debug symbol files, in ~/, one folder per date. Window > Organizer lists them under Archives.
Is it safe to delete? Only the ones you didn't ship. Apple says to keep the archive of every build you distribute: without its dSYM, you may not be able to turn a crash report's addresses back into function names and line numbers. Test builds that never reached anyone can go. To see which dates take the most space:
du -sh ~/Library/Developer/Xcode/Archives/* | sort -h
iOS DeviceSupport
When you connect an iPhone or iPad to run or debug an app, Xcode copies support files for that device's OS version into ~/, one folder per version.
Is it safe to delete? Yes, for versions you no longer use. Xcode makes a folder again when you next connect a device on that version. Apple's engineers note that these folders also symbolicate crash logs from that version, so keep the ones you still support. To see them by size:
du -sh ~/Library/Developer/Xcode/"iOS DeviceSupport"/* | sort -h
Then move the version folders you don't need to the Trash.
Swift Package Manager cache
Swift packages are cached in ~/. To clear it:
swift package purge-cache
Xcode also has File > Packages > Reset Package Caches for the open project. Packages download again when a project next needs them.
CocoaPods cache
CocoaPods keeps downloaded pods in ~/. See what's there with pod cache list, and clear all of it with:
pod cache clean --all
The next pod install downloads whatever it needs again.
Simulators and simulator runtimes
Simulator devices are the iPhones and iPads in your run destination menu, each with its own apps and data, in ~/. Simulator runtimes are the operating systems they run, installed as disk images. Apple's engineers advise clearing both with Xcode or simctl, not by deleting folders in Finder.
Delete simulators you can't use
Simulators your current Xcode no longer supports only take space. Remove them all with:
xcrun simctl delete unavailable
To remove single simulators, use Window > Devices and Simulators in Xcode.
Reset every simulator
To wipe every simulator's apps and data but keep the devices, shut them down and erase them:
xcrun simctl shutdown all
xcrun simctl erase all
Only do this if nothing in them matters.
Remove runtimes you don't need
In recent versions of Xcode, open Xcode > Settings and click Components. Xcode lists what's installed and how much storage you'd recover by removing each one. Click the info button next to a runtime, then click Delete.
From Terminal, list the runtimes and delete one by its identifier:
xcrun simctl runtime list
xcrun simctl runtime delete <identifier>
Or remove every runtime you haven't used in 90 days, checking the list first with --dry-run:
xcrun simctl runtime delete --notUsedSinceDays 90 --dry-run
Drop --dry-run to delete them. The Components pane can download any runtime again later.
node_modules and JavaScript package caches
JavaScript projects use space twice: once in each project's node_modules folder, and again in the package manager's shared cache.
Find and delete node_modules
Old projects keep their node_modules long after you've moved on. To list every one under your projects folder by size, biggest last, run this, replacing ~/Code with your own folder:
find ~/Code -type d -name node_modules -prune -exec du -sh {} + | sort -h
-prune keeps find out of each match, so you get one line per project. Nothing is deleted yet. Remove the ones you don't need, one at a time:
rm -rf ~/Code/old-project/node_modules
Or remove every one under that folder:
find ~/Code -type d -name node_modules -prune -exec rm -rf {} +
rm -rf skips the Trash. What it removes is gone at once. Point these commands at your projects folder only, never your home folder or ~/Library: some apps and editor extensions ship their own node_modules.
To get a project's dependencies back, run its install command, such as npm install or pnpm install. With pnpm, node_modules holds hard links into pnpm's store, so deleting it frees little until you prune the store.
npm cache
npm keeps every package it downloads in ~/.npm/_cacache. Its documentation says clearing it should only ever be needed to reclaim disk space. npm cache verify trims data npm no longer needs; to empty it completely:
npm cache clean --force
The --force is required. Check the size first with du -sh ~/.npm/_cacache.
pnpm store
pnpm keeps every package version in its store, ~/Library/pnpm/store on a Mac by default (pnpm store path prints it). It doesn't remove packages on its own, even once no project uses them. To remove those:
pnpm store prune
pnpm says this has no side effects on your projects. Prune now and then rather than constantly, or switching to a branch with older dependencies means downloading them again.
Yarn and Bun
Yarn 1 keeps a global cache: yarn cache dir shows where, and yarn cache clean empties it. In Yarn 2 and later, clear the shared global cache with:
yarn cache clean --mirror
Without --mirror, modern Yarn clears the current project's local cache instead, and some projects commit that folder to git.
Bun keeps its global cache in ~/.bun/install/cache. bun pm cache prints the path, and this clears it:
bun pm cache rm
Homebrew
Homebrew keeps old versions of what you upgrade, plus the downloads. It tidies up after installs and upgrades, cleans everything every 30 days, and removes downloads over 120 days old. To clean now, preview first:
brew cleanup -n
brew cleanup
brew cleanup removes old versions of installed formulae, stale lock files and outdated downloads. To delete every cached download, not only the old ones:
brew cleanup --prune=all
brew autoremove uninstalls formulae that were only dependencies of something you've since removed. Check its list first:
brew autoremove -n
brew autoremove
To see how big Homebrew's download cache is, run du -sh "$(brew --cache)".
Docker
Docker Desktop keeps its images, containers, volumes and build cache inside one disk image. Pruning frees space inside it, which can take a few minutes to show up in macOS. Start by seeing what's using the space:
docker system df
It shows your images, containers and local volumes, with how much of each could be reclaimed. Add -v for a line per item. Then prune:
docker system prune
By default this removes stopped containers, networks no container uses, dangling images and unused build cache. Two flags go further:
-aalso removes every image no container uses, not only dangling ones.--volumesalso removes anonymous volumes no container uses. Volumes can hold database data, so leave this off unless you know what's in them.
docker builder prune clears only the build cache; add -a for all unused build cache, not just dangling entries.
The Docker Desktop disk image
In Docker Desktop, Settings > Resources > Advanced shows the disk usage limit, the most space Docker may use, and the disk image location. To move the image to another drive, use Browse there, not Finder, or Docker can lose track of it.
Finder may show the file, Docker.raw, at its maximum size. For the space it really uses, read the first number this prints:
ls -klsh ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
Shrinking the disk image wipes Docker. Docker's documentation warns that lowering its size deletes the current disk image, with every container and image in it.
Rust and Go
Cargo registry and git caches
Cargo downloads crates into ~/.cargo/registry/cache as compressed .crate files and unpacks them into ~/.cargo/registry/src. Dependencies pulled from git live in ~/.cargo/git. Check the total with du -sh ~/.
The Cargo book says any part of this cache can be removed, and Cargo restores what a build needs. Since Rust 1.88, Cargo also removes downloaded files unused for three months by itself. For the space now:
rm -rf ~/.cargo/registry/cache ~/.cargo/registry/src ~/.cargo/git
Leave ~/.cargo/bin, which holds the tools you installed with cargo install or rustup, and the config.toml and credentials.toml files beside it.
Cargo target folders
Each Rust project also builds into its own target folder at the root of its workspace. To delete one, run this in the project, dry run first:
cargo clean --dry-run
cargo clean
To find target folders across your projects, this lists each target that sits next to a Cargo.toml, so folders that only happen to be called target are left out:
find ~/Code -type d -name target -prune -exec test -e {}/../Cargo.toml \; -exec du -sh {} + | sort -h
Go module and build caches
Go keeps downloaded modules in ~/go/pkg/mod unless you've changed GOPATH (go env GOMODCACHE prints it). Go makes its folders read-only, so deleting it by hand hits permission errors. Use Go's own command:
go clean -modcache
Modules download again on the next build. The build cache, ~/, trims entries you haven't used recently by itself, and go clean -cache empties it at once.
Gradle and Android Studio
Gradle caches
Gradle keeps dependencies and its build cache in ~/.gradle/caches, and the Gradle versions your wrappers download in ~/.gradle/wrapper/dists.
Gradle cleans both itself. By default it deletes downloaded files unused for 30 days, files it created, including build cache entries, after 7 days, and Gradle versions unused for 30 days. For the space at once, stop the daemons and delete the caches:
./gradlew --stop
rm -rf ~/.gradle/caches
Run the first line in a project that uses the Gradle wrapper, or use gradle --stop. Either stops only daemons of that Gradle version. The next build downloads everything again. Don't delete ~/.gradle as a whole: its gradle.properties can hold settings and credentials.
Android SDK and emulators
Android Studio downloads SDK platforms, build tools and emulator system images for each Android version you use. To remove the ones you don't need, choose Tools > SDK Manager, clear their checkboxes, and click Apply.
Each virtual device also keeps its own apps and data. In Device Manager, open the menu next to a virtual device and choose Wipe Data to empty it, or Delete to remove it.
Python, Conda and JetBrains IDEs
pip cache
pip caches the packages it downloads and builds in ~/Library/Caches/pip on a Mac. pip cache info shows how big it is, and this empties it:
pip cache purge
If you only have pip3, use pip3 cache purge or python3 -m pip cache purge.
Conda
Preview what Conda would remove from its package cache, then clean it:
conda clean --all --dry-run
conda clean --all
--all removes the index cache, unused packages, tarballs, temporary files and logs. Conda only checks the environments listed by conda info --envs, so if you keep others, skip it.
JetBrains IDE caches
JetBrains IDEs such as IntelliJ IDEA and PyCharm keep caches and Local History in ~/, one folder per product and version, with logs in ~/Library/Logs/JetBrains.
The IDE deletes old versions' cache and log folders after 180 days without an update, and Help > Delete Leftover IDE Directories clears them sooner. For the version you use now, File > Invalidate Caches clears its caches when the IDE restarts. Leave ~/ alone: it holds your settings and plugins.
What never to delete
Caches come back. These don't, or not easily:
- Your source folders. They can hold work that exists nowhere else. Clean inside a project with the tool's own command, never by deleting the project.
.gitfolders. The.gitfolder is the repository itself: every commit, branch and stash. Delete it and your files stay, but the history and anything you haven't pushed are gone.~/Library/Keychainsand your signing certificates. Your keychains hold passwords and the private keys behind your code signing certificates. Without its private key, a certificate can't sign anything, and you'd need a new one.- Provisioning profiles you still need. Recent versions of Xcode keep them in
~/, older ones inLibrary/ Developer/ Xcode/ UserData/ Provisioning Profiles ~/. Xcode fetches the profiles it manages again, but one you installed by hand can be harder to replace.Library/ MobileDevice/ Provisioning Profiles - Archives of builds you shipped. Their dSYM files are what symbolicate crash reports from those builds.
- Config files beside the caches.
~/.npmrc,~/and.cargo/ credentials.toml ~/hold settings and sometimes tokens. Delete cache folders, never a tool's whole home folder..gradle/ gradle.properties
The fast way: let Safai do it
Safai's Smart scan finds Xcode DerivedData, the npm cache, the pnpm store, Cargo's registry cache and sources and the Go module cache, along with app caches, logs and the Trash. It shows you everything, biggest first, and Wash it all away clears it in one click.
Nothing is deleted outright: it waits in Safai Trash until you empty it, and you can put any of it back. Safai never touches anything inside a git repository or a folder holding one, app bundles, cloud-synced folders, keychains or backups. node_modules, Docker, simulators and Archives stay yours to manage.
$29.99 once, for Mac and Windows. No subscription, no account, and nothing leaves your Mac. Needs macOS 13.3 or later.
Get Safai, from $29.99Questions
Is it safe to delete Xcode DerivedData?
Yes. DerivedData holds build files, indexes and logs that Xcode makes again the next time you build. Quit Xcode first, and expect the next build and indexing to take longer than usual.
Where is Xcode DerivedData located?
By default it is in ~/Library/Developer/Xcode/DerivedData in your home folder. To check, open Xcode Settings and click Locations. The small arrow next to the Derived Data path opens the folder in Finder.
Does npm cache clean delete node_modules?
No. npm cache clean --force empties the shared download cache in ~/.npm/_cacache. Each project keeps its node_modules folder until you delete it, and running npm install in the project puts it back.
Does docker system prune delete volumes?
Not by default. It removes stopped containers, networks no container uses, dangling images and unused build cache. Volumes stay unless you add --volumes, and unused images that are not dangling go only when you add -a.
Can I delete the iOS DeviceSupport folder?
You can delete the version folders inside it. Xcode makes a folder again the next time you connect a device running that version. They also help symbolicate crash logs from that version, so keep the ones for versions you still support.
What does brew cleanup remove?
Old versions of installed formulae, stale lock files and outdated downloads. By default it removes downloads more than 120 days old. Add --prune=all to remove every cached download, or -n to see the list first.