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:
| What | Where | Safe to delete | Comes back |
|---|---|---|---|
| Build output, one per project | <project>/target | Yes | On the next cargo build, after a full rebuild |
| Toolchains | ~/.rustup/toolchains | Ones you don't use | rustup toolchain install |
| Downloaded crates | ~/.cargo/registry, ~/.cargo/git | cache, src and checkouts inside them | When a build needs them |
I measured mine on 5 November 2026 (Cargo 1.99.1, rustup 1.29.2):
$ 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/debugforcargo build,target/releasefor--release, and more for custom profiles. - One per target triple. Cross-compiling with
--targetaddstarget/<triple>/debugandrelease. - Incremental caches.
target/debug/incrementalkeeps 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
targetis 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:
$ 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:
$ 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.
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:
$ 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.
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:
$ mv ~/.cargo/registry/cache ~/.cargo/registry/src ~/.Trash/ $ mv ~/.cargo/git/checkouts ~/.Trash/
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:
$ 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:
$ 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:
$ 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.

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.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
- The Cargo Book: cargo clean
- Rust 1.88.0 release notes: Cargo automatic cache cleaning
- cargo-sweep on GitHub
- The rustup book: profiles
- Measured on this Mac on 5 November 2026 (macOS 26.5.1, Cargo 1.99.1, rustup 1.29.2):
duon~/.rustupand~/.cargo,cargo clean -nandcargo cleanon a new project,cat target/CACHEDIR.TAG,tmutil isexcluded target,cargo clean --help,cargo -Z help.