Rust Guide

Cleaning Rust Cargo Registry, Git Checkouts, and Rustup Toolchains

Last updated: 2026-04-06

Rust developers accumulate crate downloads in ~/.cargo/registry, git checkouts in ~/.cargo/git, and multiple toolchain versions under ~/.rustup/toolchains. After months of development across multiple projects, these directories can consume 3–10 GB or more. Each project also generates a target/ directory with compiled artifacts that can be several gigabytes per project. All of these are regenerable — Cargo will re-download crates and recompile as needed.

What is the Cargo registry?

The Cargo registry at ~/.cargo/registry stores downloaded crate source files and metadata. Every dependency your projects use gets cached here, including all historical versions that were ever resolved. The registry index at ~/.cargo/registry/src contains extracted source code for every crate version. Over time this grows significantly, especially if you work on projects with many dependencies.

Cargo git checkouts

When your Cargo.toml depends on git repositories directly (rather than published crates), Cargo clones them into ~/.cargo/git. Each revision gets its own checkout. If you depend on several git-based crates or have switched between branches/revisions, this directory can grow to several hundred megabytes or more.

Rustup toolchains

Rustup manages multiple Rust toolchain versions under ~/.rustup/toolchains. Each toolchain (stable, beta, nightly, or specific versions) is a full copy of the Rust compiler, standard library, and tools — typically 500 MB–1 GB each. If you have accumulated several old toolchains, this adds up. You can list installed toolchains with `rustup toolchain list` and remove old ones with `rustup toolchain uninstall`.

Per-project target/ directories

Each Rust project generates a target/ directory containing compiled artifacts, incremental compilation data, and build script outputs. A single project's target/ can be 1–5 GB or more. CodeCleaner's Project Build Artifact Scanner finds every target/ directory across your filesystem and ranks them by size.

How CodeCleaner cleans Rust caches

CodeCleaner detects your Rust installation, calculates the size of the Cargo registry, git checkouts, and Rustup toolchains, and lets you clean the registry and git caches without removing your active toolchains. The Project Scanner separately finds and sizes every target/ directory across your projects for bulk cleanup.

Manual steps (Terminal)

You can do this manually with these commands, or use CodeCleaner to automate the process with a visual interface and safety checks.

rm -rf ~/.cargo/registry
rm -rf ~/.cargo/git
rustup toolchain list
rustup toolchain uninstall <old-version>
cargo clean  # run inside each project to delete target/

Or use CodeCleaner

CodeCleaner automates all of this with a native macOS app. It auto-detects your installed tools, scans the relevant paths in parallel, shows per-item sizes, and lets you clean safely with one click. Free scan, no account required.