Is it safe to delete ~/.cargo/registry and ~/.cargo/git?
- Yes, those two. They’re Cargo’s cache of crates and git dependencies, which Cargo extracts or downloads again. Don’t delete
~/.cargoas a whole: with rustup, itsbinfolder holdscargoandrustcthemselves. - What it costs you: the next build re-extracts or downloads the crates it needs, and needs the network for anything no longer cached.
- Does it come back? Yes. Since Rust 1.88, Cargo also trims old cache files by itself.
- SiftMac’s verdict: Rebuilds
1. What’s in ~/.cargo
~/.cargo is Cargo’s home. The Cargo Book lists what’s in it, and only part of it is cache:
| Folder or file | What it holds | Safe to clear? |
|---|---|---|
registry/index | Metadata of the crates in the registry | Yes; fetched again |
registry/cache | Downloaded crates, as .crate archives | Yes; downloaded again |
registry/src | Those archives unpacked, where rustc reads them | Yes; extracted again from registry/cache |
git/db | Bare clones of git dependencies | Yes; cloned again |
git/checkouts | The commit each project needs, checked out from git/db | Yes; checked out again |
bin | Programs from cargo install, and cargo, rustc and rustup if you use rustup | No |
config.toml, credentials.toml | Your Cargo settings and registry login | No |
The Cargo Book is relaxed about the cache: you can remove any part of it, and Cargo will do its best to restore sources by re-extracting an archive, checking out the bare repository, or downloading again.
2. Where it is
~/.cargo/registry
~/.cargo/git
Cargo’s home defaults to $HOME/.cargo, and CARGO_HOME moves it. Rust compilers themselves are managed by rustup in a folder of its own; list them with rustup toolchain list and remove old ones with rustup toolchain uninstall.
3. How big it gets
du -sh ~/.cargo/registry/* ~/.cargo/git/* 2>/dev/null
Unpacked sources in registry/src take more room than the compressed archives in registry/cache they came from, and both hold every version any of your projects has used.
4. How to clear it
Close editors running rust-analyzer and let builds finish, then remove the parts you want. In order, from cheapest to most costly to rebuild:
rm -rf ~/.cargo/registry/src/*
rm -rf ~/.cargo/git/checkouts/*
rm -rf ~/.cargo/registry/cache/*
rm -rf ~/.cargo/git/db/*
The first two only cost re-extracting and checking out again, with no download. The last two mean downloading crates and cloning git dependencies again. The Cargo Book also mentions a third-party tool, cargo-cache, that shows the size of each part and clears them selectively.
Never run rm -rf ~/.cargo to save space. If you installed Rust with rustup, that removes cargo, rustc and rustup along with every program you installed.
5. What happens afterwards
- The next
cargo buildre-extracts or downloads the crates listed inCargo.lock, at exactly those versions. - Builds run with
--offlineor--frozenfail for anything no longer cached. - Compiled output in your projects isn’t affected; for that space, see Rust target folders.
- Cargo keeps trimming by itself: since 1.88 it removes downloaded files not used for 3 months and files obtained from your own disk, such as extracted sources, not used for 1 month, except when running offline.
Questions
Can I delete the whole ~/.cargo folder?
Not if you use rustup: ~/.cargo/bin holds the cargo, rustc and rustup commands, plus programs from cargo install. Clear registry and git instead.
Does Cargo clean its cache automatically?
Since Rust 1.88, yes, unless you’re offline. If you also run a Cargo older than 1.78, which doesn’t record when cache files were used, the release notes suggest setting cache.auto-clean-frequency = "never".
How do I remove programs I installed with cargo install?
cargo install --list shows them and cargo uninstall <name> removes one. Avoid deleting files in ~/.cargo/bin by hand: Cargo keeps a record of installed programs that it expects to match.
How SiftMac handles it. SiftMac doesn’t clear ~/.cargo. Its space map labels the folder as Rust’s package registry and installed tools and advises leaving it, since the registry part downloads again but the tools are yours. For old Rust projects, Developer files lists target folders next to a Cargo.toml.
Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works