Rust disk space on a Mac: target folders, the Cargo cache and rustup toolchains

Why Rust's target folders grow to gigabytes, how to clean them all at once, what Cargo now cleans by itself, and the 920 MB of docs inside a rustup toolchain.

Short answer

A Rust project's target folder holds every build Cargo has made for it and is safe to delete: cargo clean empties it, and the next build makes it again. Cargo never removes old artifacts by itself, so across many projects it adds up to tens of gigabytes. cargo sweep --recursive --time 30 ~/Projects cleans them all at once. Cargo's download cache in ~/.cargo/registry now cleans itself (since Cargo 1.88), and most of a rustup toolchain can be its offline docs: 920 MB of 1.3 GB on my Mac.

Where Rust's space goes

Three places, from usually biggest to smallest:

WhatWhereSafe to deleteComes back
Build output, one per project<project>/targetYesOn the next cargo build, after a full rebuild
Toolchains~/.rustup/toolchainsOnes you don't userustup toolchain install
Downloaded crates~/.cargo/registry, ~/.cargo/gitcache, src and checkouts inside themWhen a build needs them

I measured mine on 5 November 2026 (Cargo 1.99.1, rustup 1.29.2):

Terminal
$ du -sh ~/.rustup ~/.cargo/registry/*
# 1.3G  ~/.rustup
#  16M  ~/.cargo/registry/index
# 338M  ~/.cargo/registry/src

Why target folders get so big

target isn't one build, it's all of them:

  • One per profile. target/debug for cargo build, target/release for --release, and more for custom profiles.
  • One per target triple. Cross-compiling with --target adds target/<triple>/debug and release.
  • Incremental caches. target/debug/incremental keeps compiler state between builds so rebuilds are fast.
  • Old artifacts. When you update a dependency, change features, or update Rust, Cargo builds new copies and keeps the old ones. Nothing in target is ever removed unless you clean it.

A small project's target is megabytes. A project with a few hundred dependencies, built in debug and release over a few months of updates, is often several gigabytes, and every project you've ever built has its own.

Find every target folder

Cargo puts a CACHEDIR.TAG file in every target folder it creates, which makes them easy to find without catching unrelated folders named target:

Terminal
$ find ~ -type f -path '*/target/CACHEDIR.TAG' -not -path '*/Library/*' 2>/dev/null \
$   | while read -r f; do du -sh "$(dirname "$f")"; done | sort -h

It only reads, so it's safe to run anywhere.

Clean one project: cargo clean

Run these inside the project. -n (dry run) shows what it would remove first:

Terminal
$ cargo clean -n          # Summary 41 files, 1.9MiB total
$ cargo clean             # Removed 41 files, 1.9MiB total
$ cargo clean --release   # only target/release
$ cargo clean --doc       # only target/doc
$ cargo clean -p serde    # only one package's artifacts

Those numbers are from a fresh cargo new project. On a real one they're usually in gigabytes.

Safe

Everything in target is rebuilt from your source and Cargo.lock. The only things you'd lose are binaries you built and haven't copied anywhere else, like a target/release executable you run from there.

Clean every project: cargo-sweep

cargo-sweep removes only old artifacts and keeps what your current builds use, so the next build isn't from scratch:

Terminal
$ cargo install cargo-sweep
$ cargo sweep --dry-run --time 30 .              # preview, this project
$ cargo sweep --recursive --time 30 ~/Projects   # every project under ~/Projects
$ cargo sweep --installed                        # artifacts from compilers you no longer have
$ cargo sweep --maxsize 10GiB                    # trim this project's target to 10 GiB

--time 30 removes files not used in 30 days. --installed is the one to run after a Rust update: it removes everything built by toolchains that aren't installed anymore.

Check first

Run sweeps when no cargo build, cargo watch or rust-analyzer is busy in that project. rust-analyzer runs cargo check in the background and writes to target too.

The Cargo cache in ~/.cargo

Since Cargo 1.88 (June 2025), Cargo cleans its own cache: it removes files downloaded from the network that haven't been used in 3 months, and files copied from your own disk after 1 month. If you're on Cargo 1.88 or later, ~/.cargo/registry mostly stays in check by itself.

To clear it now, there's no stable command (cargo clean gc exists, but only on nightly with -Z gc). Move the download folders to the Trash with no build running:

Terminal
$ mv ~/.cargo/registry/cache ~/.cargo/registry/src ~/.Trash/
$ mv ~/.cargo/git/checkouts ~/.Trash/
Check first

Never delete ~/.cargo itself. It also holds ~/.cargo/bin (everything you installed with cargo install, and on a rustup install, cargo and rustc themselves), config.toml, and credentials.toml with your crates.io token.

rustup toolchains, and their docs

Each toolchain is a full copy of the compiler and standard library. Old nightlies pile up if you pin them per project:

Terminal
$ rustup toolchain list
$ du -sh ~/.rustup/toolchains/*
$ rustup toolchain uninstall nightly-2025-06-01   # one you no longer use

The surprise on my Mac was inside the one toolchain I have:

Terminal
$ du -sh ~/.rustup/toolchains/stable-aarch64-apple-darwin/{share/doc,lib,bin}
# 920M  share/doc   (the offline Rust docs)
# 386M  lib
#  60M  bin

70% of the toolchain was rust-docs, the offline copy of the Rust book and standard library docs that rustup doc opens. rustup's default profile installs it with every toolchain. If you read the docs online:

Terminal
$ rustup component remove rust-docs
$ rustup set profile minimal   # future toolchains skip docs, clippy and rustfmt

minimal also leaves out clippy and rustfmt. Add them back with rustup component add clippy rustfmt if you use them.

Time Machine already skips target

Cargo marks every target folder it creates as excluded from Time Machine. On my Mac, tmutil isexcluded target printed [Excluded] for a brand-new project. So target folders fill your disk, not your backups, and there's no need to add them to Time Machine's exclusions by hand.

Shedi finds every Rust target folder and Cargo's downloaded cratesIt lists each target folder beside a Cargo.toml in your project folders, with its project and size, marked "check first" because the next build takes a while, plus ~/.cargo/registry/cache. You pick, and it moves them to the Trash. It doesn't remove toolchains or rust-docs; use rustup for those.
Get Shedi

To see Rust next to every other developer cache on your Mac, run diskreceipt, a free Terminal tool that only reads. For the JavaScript side, see Delete node_modules safely.

Sources

Questions

Is it safe to delete a Rust target folder?

Yes. target holds only build output: compiled dependencies, incremental caches and your binaries. The next cargo build makes it again. The cost is time, since the first build after cleaning compiles every dependency from scratch. Copy out any binary you want to keep first.

Why is my Rust target folder so big?

Cargo keeps a separate build for each profile (debug and release), for each target triple, and for each set of features, plus incremental compilation caches. It never removes artifacts from old dependency versions or old compilers, so the folder grows with every update until you run cargo clean.

How do I clean every target folder on my Mac at once?

Install cargo-sweep (cargo install cargo-sweep) and run cargo sweep --recursive --time 30 ~/Projects to remove artifacts not used in 30 days in every project under that folder. Add --dry-run first to see what it would remove.

Can I delete ~/.cargo/registry?

The cache and src folders inside it, yes: Cargo downloads the crates again when a build needs them. Since Cargo 1.88 it also removes downloaded files it hasn't used in 3 months by itself. Don't delete ~/.cargo as a whole: it holds your installed binaries, config.toml and registry credentials.

Why is ~/.rustup so big?

Each toolchain is a full compiler, standard library and, with rustup's default profile, the offline documentation. On my Mac the stable toolchain was 1.3 GB, and 920 MB of that was rust-docs. rustup component remove rust-docs deletes it; rustup doc then won't work offline.

Does Time Machine back up Rust target folders?

No. Cargo marks every target folder as excluded from Time Machine when it creates it, and tags it with a CACHEDIR.TAG file. They take disk space, not backup space.