Language toolchains & SDKs

Rust target/ Folders Are Huge: How to Clean Cargo Build Artifacts in 2026

If you have been writing Rust on your Mac for any length of time, you have probably noticed that your disk is disappearing faster than expected. The rust target folder taking up space is one of the most common storage complaints among Rust developers, and for good reason: a single mid-sized project can accumulate 5–15 GB of compiled artifacts in its target/ directory, and if you have a dozen active or archived projects, that figure multiplies fast. On Apple Silicon Macs running macOS Sequoia or Tahoe, storage is often limited to 256–512 GB, making every gigabyte meaningful.

Why Does the target/ Folder Get So Large?

Rust compiles each crate and its dependencies separately, then links them together. Unlike interpreted languages, there is no shared runtime that skips recompilation. Every dependency you list in Cargo.toml gets compiled from source into machine code and cached under target/ so incremental builds are fast. The tradeoff is disk space.

Inside a typical target/ directory you will find multiple build profiles:

  • target/debug/ — unoptimized build with full debug symbols (often the biggest)
  • target/release/ — optimized build, smaller binary but still has intermediate objects
  • target/doc/ — generated documentation
  • target/.fingerprint/, target/deps/, target/incremental/ — incremental compilation state

The incremental/ subdirectory alone can top several gigabytes because Rust stores detailed compilation metadata to speed up future builds.

Where Cargo Stores Data on macOS

Beyond the per-project target/ folder, Cargo maintains a global registry and source cache in your home directory. Understanding both locations is essential before you start deleting.

Location What lives there Typical size Safe to delete?
~/project/target/ Per-project build artifacts, debug info, incremental state 3–15 GB per project Yes — rebuilt on next cargo build
~/.cargo/registry/cache/ Downloaded .crate files (compressed source tarballs) 500 MB – 3 GB Yes — re-downloaded on demand
~/.cargo/registry/src/ Unpacked crate source trees used during compilation 1–5 GB Yes — unpacked again when needed
~/.cargo/git/ Cloned git repositories for git-sourced dependencies 100 MB – 2 GB Yes — re-cloned on demand
~/.cargo/bin/ Installed CLI tools (cargo install outputs) 50–500 MB Only if you no longer need the tool
~/.rustup/toolchains/ Installed Rust toolchain versions (stable, beta, nightly, older) 1–4 GB per toolchain Yes for unused toolchains

How to Check How Much Space Cargo Is Using

Before deleting anything, measure what you actually have. Open Terminal and run:

du -sh ~/.cargo
du -sh ~/.rustup

To find all target/ directories under your code folder (replace ~/code with your own projects root):

find ~/code -type d -name target -maxdepth 4 | xargs du -sh 2>/dev/null | sort -rh | head -20

This prints the largest offenders first. On a machine with several Rust projects it is common to see totals of 30–60 GB spread across multiple workspaces.

How to Clean Rust Cargo Artifacts: Step-by-Step

Step 1 — Use cargo clean for a single project

The safest and most official method is to run Cargo's own clean command from inside the project directory:

cd ~/code/my-rust-project
cargo clean

This removes the entire target/ directory for that workspace. The next cargo build will recompile everything from scratch, so expect a longer first build afterward. Use this when you are done with a sprint or are archiving a project.

Step 2 — Remove target/ folders from archived projects manually

For projects you have not touched in months, there is no need to run Cargo at all. Just delete the folder directly:

rm -rf ~/code/old-project/target

Check that you are not deleting build outputs you need (such as a release binary you have not archived elsewhere) before running this.

Step 3 — Clean the global Cargo cache

Cargo does not yet ship a built-in command for pruning the registry cache, but the third-party tool cargo-cache fills that gap well. Install it with:

cargo install cargo-cache

Then get a breakdown of what is taking space:

cargo cache

To remove only the registry source trees (which are always reproducible from the compressed caches):

cargo cache --autoclean

Or to do a full wipe of the registry src and git checkouts (keeping the compressed .crate tarballs so re-extraction is fast):

cargo cache -e all

Step 4 — Remove unused Rust toolchains

Each toolchain under ~/.rustup/toolchains/ takes 1–2 GB. If you installed nightly six months ago to test a feature and never updated it, reclaim that space:

rustup toolchain list
rustup toolchain uninstall nightly-2025-09-01-aarch64-apple-darwin

On Apple Silicon, toolchain names include aarch64-apple-darwin; on Intel Macs they include x86_64-apple-darwin. You can safely remove any toolchain you do not actively use — the latest stable will remain and Rust projects that require a specific toolchain will re-download it when you next enter that project directory.

Automating the Cleanup: cargo sweep

Deleting everything is not always what you want. If a project is under active development, wiping its target/ means a full recompile on the next build. cargo-sweep is a smarter alternative: it deletes only build artifacts that are older than a configurable threshold and are no longer needed by the current Rust toolchain version.

cargo install cargo-sweep
# Remove artifacts older than 30 days across all projects
cargo sweep --time 30 --recursive ~/code

Running this as a weekly launchd job or simply adding it to your shell profile keeps disk use under control without sacrificing incremental build speed for active projects.

Rust Cleanup as Part of a Broader Disk Audit

Cargo artifacts are one category of developer storage sprawl. If you also work with Node.js, you likely have node_modules trees consuming similar amounts — see the guide on cleaning up node_modules on Mac for a parallel walkthrough. And if Xcode is in the picture, ~/Library/Developer/Xcode/DerivedData can rival even the largest target/ folders — that is covered in the post on why Xcode takes up so much space.

When you want to see the full picture across Cargo caches, Rustup toolchains, node_modules, DerivedData, and ~/Library/Caches all at once, a tool like Crumb can audit all of these at once and show what is safe before you delete.

How Much Space Can You Expect to Recover?

Results vary depending on how many projects and toolchains you have installed, but here are realistic ranges:

  • Cleaning target/ from 5 archived projects: 20–50 GB
  • Pruning the global Cargo registry src with cargo cache --autoclean: 1–4 GB
  • Removing one unused nightly toolchain: 1–2 GB
  • Full registry and git cache wipe (all crates re-downloaded next build): 2–8 GB

On a developer machine with a moderately active Rust history, reclaiming 20–60 GB is common. None of this data is irreplaceable: it all regenerates from your source code and the crates.io registry.

Preventing target/ Bloat Going Forward

A few habits keep Cargo from quietly eating your disk:

  • Set a global target directory outside your project tree by adding build.target-dir = "/Users/you/.cargo/build-cache" to ~/.cargo/config.toml. This puts all build artifacts in one place that is easy to monitor and wipe.
  • Enable sccache as a shared compiler cache if you work on multiple machines or in CI — it deduplicates compilation work across projects.
  • Run cargo sweep --time 14 --recursive ~/code on a schedule to prune stale artifacts automatically.
  • Archive projects by running cargo clean before moving them to cold storage or compressing them.

Rust's compile caching is genuinely valuable for fast iteration, but it only helps if you are actively building. Artifacts from projects you finished six months ago are pure waste, and the commands above make removing them a matter of seconds.

Reclaim your disk in one click

Crumb audits your whole Mac, tells you what's safe to delete, and frees the space in seconds — private, local, and Apple-notarized.

Download Crumb for macOS

Frequently asked questions

Is it safe to delete the Rust target/ folder?
Yes. The target/ folder contains only compiled artifacts generated from your source code. Deleting it means the next cargo build will recompile everything from scratch, which takes longer, but no source code or configuration is lost.
Where is the Rust Cargo cache stored on Mac?
Cargo stores its global registry and downloaded crate source files under ~/.cargo/registry/ and git dependencies under ~/.cargo/git/. Installed toolchains live in ~/.rustup/toolchains/. Per-project build outputs are in the target/ folder inside each project directory.
Will cleaning Cargo artifacts affect my installed Rust tools?
No. CLI tools installed with cargo install are stored in ~/.cargo/bin/ as compiled binaries and are separate from the build cache. Cleaning target/ directories or pruning ~/.cargo/registry/ does not touch those binaries.
How do I delete only old or stale Rust build artifacts, not everything?
Use cargo-sweep (cargo install cargo-sweep) and run cargo sweep --time 30 --recursive ~/code to remove artifacts older than 30 days. This keeps incremental build state for projects you are actively working on while reclaiming space from dormant ones.
How much space can I recover by cleaning Rust build artifacts?
On a machine with several projects it is realistic to recover 20–60 GB. Each project's target/ directory can be 5–15 GB, and the global Cargo registry src folder typically adds another 1–5 GB on top of that.