What is ~/.cargo/registry, and is it safe to delete?

The ~/.cargo/registry folder holds Rust crates that Cargo downloads and unpacks, and it is safe to delete because Cargo fetches them again on the next build.

Shiva ChandraMaker of Clean House · · 2 min read
Short answer

~/.cargo/registry is where Cargo stores downloaded Rust crates, their unpacked sources and the registry index. It is safe to delete. The next cargo build downloads whatever crates it needs again, so you need a network connection. Your own projects and their target folders are not affected.

Path
~/.cargo/registry
What it is
Downloaded .crate archives, unpacked sources and the registry index
Typical size
Hundreds of megabytes to several gigabytes; Cargo does not cap it
Made by
Cargo (Rust)
Safe to delete?
Safe to clear
Comes back?
Yes, Cargo downloads crates again on the next build, which needs a network connection

What is in this folder?

The Cargo Book describes the layout: downloaded dependencies sit in registry/cache as .crate archives, and registry/src holds the extracted files that the compiler reads. Git dependencies are cloned separately into ~/.cargo/git.

Because crates are stored twice (archive and unpacked), the folder grows quickly on a Mac that has built many Rust projects.

Is it safe to delete?

Yes. Nothing in the registry folder is unique: crates come from crates.io. Projects with a Cargo.lock fetch the same versions. The exception is if a crate version has been yanked or removed since, in which case an offline copy in your cache may be your only one.

Do not delete the rest of ~/.cargo. It holds bin (installed tools such as cargo-installed programs) and credentials.toml, which holds your login token.

How do I clear it by hand?

  1. Stop any running cargo build or rust-analyzer session.
  2. Delete the registry folder only.
  3. Build a project, and Cargo downloads crates again.
rm -rf ~/.cargo/registry
rm -rf ~/.cargo/git
The second line is optional and removes cached Git dependencies. Run cargo clean inside a project to remove its target folder.

How do I stop it growing?

Delete the registry now and then. For project build output, cargo clean in finished projects frees often larger space than the registry.

How Clean House handles it

Clean House recognizes ~/.cargo/registry as a Rust crates cache and ~/.cargo/git as a Cargo Git cache, both made by Cargo and both marked as downloading again. It treats ~/.cargo/credentials as protected and never offers it.

Questions

Is it safe to delete ~/.cargo/registry?

Yes. Cargo downloads crates again on the next build. You need a network connection.

What is in ~/.cargo?

bin (installed tools), registry and git (download caches) and credentials.toml for your login token.

How do I clean Rust build files?

Run cargo clean in the project to remove its target folder.

Sources

  1. The Cargo Book: Cargo Home
  2. Rust Blog: Cargo cache cleaning