If you work with Rust on macOS, you have probably noticed that disk usage climbs faster than you expect. Understanding the cargo cache location on Mac is the first step to reclaiming that space safely. The Cargo package manager stores downloaded crates, compiled artifacts, and registry indexes in a hidden home-directory folder, and on an active machine it can grow to several gigabytes without any warning. This guide explains exactly where the cache lives on macOS Sequoia and Tahoe (Apple Silicon and Intel), which parts are safe to delete, and how to clean them up without breaking your projects.
Where Is the Cargo Cache Stored on macOS?
Cargo follows the XDG convention by default but overrides it with the CARGO_HOME environment variable if you have set one. On a standard Mac installation the root of all Cargo data lives at:
~/.cargo/— the defaultCARGO_HOME
Inside that directory, the cache-relevant subdirectories are:
~/.cargo/registry/— downloaded crate source archives and the crates.io index~/.cargo/git/— Git-based crate checkouts (crates sourced directly from GitHub or other repos)~/.cargo/bin/— installed binaries (cargo installoutput); do not clear this
Compiled build artifacts, on the other hand, live inside each project's own target/ directory — typically at ~/path/to/your-project/target/ — and are completely separate from ~/.cargo. That distinction matters a great deal when deciding what to remove.
Folder-by-Folder Size Breakdown
The table below shows the typical contents and approximate sizes you might see on a Mac that has been doing active Rust development for six months to a year:
| Path | What it contains | Typical size | Safe to delete? |
|---|---|---|---|
~/.cargo/registry/cache/ |
Compressed .crate archives downloaded from crates.io |
500 MB – 3 GB | Yes — Cargo re-downloads on next build |
~/.cargo/registry/src/ |
Unpacked source trees used during compilation | 1 GB – 5 GB | Yes — rebuilt from the cache archives above |
~/.cargo/registry/index/ |
Git-cloned crates.io index (package metadata) | 200 MB – 600 MB | Yes — re-fetched automatically |
~/.cargo/git/db/ |
Bare Git repositories for git-sourced crates | Varies widely | Yes — re-cloned on next build |
~/.cargo/git/checkouts/ |
Working-tree checkouts of git crates | Varies widely | Yes — re-checked-out on next build |
~/.cargo/bin/ |
Binaries installed via cargo install |
50 MB – 500 MB | No — you lose the installed tools |
project/target/ |
Per-project incremental build artifacts | 1 GB – 10 GB per project | Yes — cleaned by cargo clean |
Is It Safe to Clear the Cargo Cache on Mac?
The short answer is yes — with one important exception. The registry/ and git/ subdirectories are pure download caches. Deleting them does not remove any of your code, and Cargo will transparently re-fetch whatever it needs the next time you run cargo build or cargo test. Your first build after clearing will take longer (and require an internet connection), but nothing will break permanently.
The folder you must never delete blindly is ~/.cargo/bin/. Every binary you installed with cargo install — tools like cargo-watch, cargo-expand, ripgrep, fd, or bat — lives there. Removing it means you have to reinstall each tool from source, which can take considerable time.
Similarly, leave ~/.cargo/env and ~/.cargo/config.toml untouched; those are configuration files, not cache.
How to Clear the Cargo Cache on Mac (Step by Step)
There are two main approaches: using the official cargo cache subcommand (recommended) or deleting directories manually.
Option 1 — Use cargo-cache (Recommended)
- Install the subcommand once:
cargo install cargo-cache - Preview what would be freed:
cargo cache— this prints a size report without deleting anything. - Remove only the registry source trees (safest first pass):
cargo cache --autoclean - For a more aggressive clean that also removes old registry cache entries:
cargo cache --remove-dir all
The --autoclean flag is smart enough to keep the compressed .crate archives (so future builds are faster) while discarding the unpacked source trees that consume the most space.
Option 2 — Manual Deletion
- Check the current size:
du -sh ~/.cargo/registry ~/.cargo/git - Remove only registry sources and archives:
rm -rf ~/.cargo/registry/src ~/.cargo/registry/cache - Remove the crates.io index (will be re-cloned):
rm -rf ~/.cargo/registry/index - Remove git-sourced crates:
rm -rf ~/.cargo/git
Leave ~/.cargo/bin/ alone unless you intend to reinstall every tool by hand.
Cleaning Per-Project Build Artifacts
The target/ directory inside each Rust project is often the single biggest consumer of disk space. Clean it with Cargo's built-in command from inside your project folder:
cargo clean— removes the entiretarget/directory for that project
If you have dozens of projects spread across your Mac, finding and removing all of those target/ directories manually is tedious. You can locate them with:
find ~ -name target -path "*/Cargo.toml" -prune -o -name target -type d -print 2>/dev/null
A tool like Crumb can audit all of these build-artifact folders at once and show what is safe to delete before anything is actually removed, which is helpful when you have multiple projects and are not sure which target/ directories belong to active projects versus abandoned experiments.
How Much Space Can You Realistically Reclaim?
Results vary considerably based on how long you have been using Rust and how many crates you pull in. In practice, a developer who has been active for a year with several medium-sized projects typically sees:
- Registry sources and cache: 2–6 GB freed
- Per-project
target/directories: 5–20 GB freed across all projects - Git-sourced crates: a few hundred MB to 1 GB freed
Total savings of 10–25 GB are not unusual. If you also work with other language toolchains — Node.js node_modules, Java's Maven at ~/.m2/repository/, or Xcode's DerivedData at ~/Library/Developer/Xcode/DerivedData/ — the combined total can be substantially higher. For a full picture of what language toolchains are eating on your drive, see what is taking up space on your Mac.
Apple Silicon vs. Intel: Does the Cache Location Differ?
No. The Cargo cache location is the same on both Apple Silicon (M1/M2/M3/M4) and Intel Macs — ~/.cargo/ in your home directory. The only architecture-related difference you might notice is that on Apple Silicon you can have separate builds for aarch64-apple-darwin and x86_64-apple-darwin targets inside your target/ directory (for cross-compilation or Rosetta testing), which can roughly double per-project build artifact sizes.
Keeping the Cache Under Control Long-Term
Rather than doing a single large cleanup and then letting things grow back, consider these habits:
- Run
cargo cache --autocleanonce a month to prune stale source trees automatically. - Run
cargo cleanin projects you are done with before archiving or deleting them. - Set a reminder to audit
~/.cargo/registry/size withdu -sh ~/.cargo/registryevery few months. - If disk space is perpetually tight, consider setting
CARGO_HOMEto a location on an external drive for large personal projects while keeping the default path for work projects.
Understanding the interplay between the shared Cargo cache and per-project target/ directories is the key insight. The cache is a convenience layer; the target/ directories are where the real storage cost usually lives. For a broader look at how developer caches fit into overall Mac storage, the guide on what cache files are on a Mac is a useful companion read.