Is it safe to delete ~/.cargo on Mac?
Safe with care~/.cargo
Only the caches inside it. What Rust's Cargo keeps in ~/.cargo, which parts rebuild, which hold your tools and logins, and how to clear it safely.
Verdict: Safe with care. The download caches inside ~/.cargo/registry and ~/.cargo/git are safe to delete, because Cargo restores them on the next build. Don't delete ~/.cargo itself: it can hold your Rust tools in bin, your Cargo settings in config.toml and your registry login in credentials.toml.
What lives in ~/.cargo
~/.cargo is Cargo's home, unless you set CARGO_HOME to move it. The Cargo book's page on Cargo home lists what goes in it:
bin: programs installed withcargo install, and the commands rustup installs.config.toml: Cargo's global settings.credentials.toml: your private login fromcargo login, used to publish to a registry..crates.tomland.crates2.json: Cargo's record of whatcargo installput inbin. The book says not to edit them by hand.registry/cache: every crate you have downloaded, as compressed.cratearchives.registry/src: those archives unpacked, where the compiler reads the source.registry/index: the registry's index of available crates.git/dbandgit/checkouts: clones of git dependencies and the commits your projects use.
On the macOS 15.5 Mac we checked this on, ~/.cargo came to 960 MB. Unpacked sources in registry/src made up 824 MB of that, with 99 MB of archives in registry/cache and 37 MB of index. There was no bin, because rustup had come from Homebrew; the toolchains sat separately in ~/.rustup, at 1.3 GB.
What happens if you delete it
The Cargo book is reassuring about the cache: "you can always remove any part of the cache and Cargo will do its best to restore sources". In practice:
registry/srcis re-extracted from the archives inregistry/cachethe next time a build needs it. That is quick and needs no network.registry/cacheis downloaded again from crates.io, so it needs a connection.git/checkoutsis recreated fromgit/db, andgit/dbis cloned again if you remove it.bin,config.tomlandcredentials.tomlare lost for good. Your installed tools disappear, possibly includingcargoandrustcif rustup put them there, and you needcargo loginagain before you can publish.
Cargo also clears out old files by itself now. The Rust 1.88 release notes say Cargo removes files downloaded from the network once they haven't been used for 3 months, and files obtained from your own Mac after 1 month.
How to check its size safely
These commands only read:
du -sh ~/.cargo/* 2>/dev/null | sort -h
du -sh ~/.cargo/registry/* ~/.cargo/git/* 2>/dev/null
The first lists each part of the Cargo home by size, and the second breaks down the caches.
In Finder, choose Go > Go to Folder, type ~/.cargo and press Return. The folder is hidden because its name starts with a dot. Select a folder and choose File > Get Info for its size.
The safest way to get the space back
- Let any running
cargo buildor editor background check finish. - Move the unpacked sources to the Bin first. They are often the biggest part and the cheapest to rebuild:
trash ~/.cargo/registry/src
The trash command comes with macOS 14 Sonoma and later.
- If you need more room, move the archives and git checkouts as well:
trash ~/.cargo/registry/cache ~/.cargo/git/checkouts
- Build a project you work on. When it succeeds, empty the Bin.
The Cargo book also points to cargo-cache, a third-party tool that shows the size of each part and clears selected ones.
Warning: rm -rf ~/.cargo deletes your tools, settings and registry login along with the caches, skipping the Bin. Clear the cache folders on their own instead.
What never to touch
bin,config.tomlandcredentials.toml..crates.tomland.crates2.json. Cargo uses them to track installed tools.- The caches during a build.
~/.rustupby hand. To remove an old toolchain, runrustup toolchain list, thenrustup toolchain uninstallwith its name.
A project's own build output goes in its target folder, which is often far bigger than ~/.cargo and rebuilds with cargo build. Our guide to deleting node_modules and other build folders covers target too. For other developer caches, see the ~/.gradle and ~/.cache pages.
How Headroom helps
Headroom's Clean scan lists Rust crate downloads in ~/.cargo/registry/cache under Developer caches once they pass 1 MB, with the note that Cargo downloads crates again when needed. They are ticked by default and deleted for good when you clean. Headroom leaves bin, your settings, your login, registry/src and git alone. Under Project build files it also lists target folders in projects with a Cargo.toml that haven't been edited for 14 days. The scan is free, and the $19 one-time licence clears what you tick. See the cleaner or download Headroom.
Questions
Can I delete ~/.cargo/registry?
Yes. Cargo re-extracts or downloads crates as builds need them. The first build afterwards is slower and needs a network connection.
Does Cargo clean its own cache?
Since Rust 1.88, yes. Cargo removes files it downloaded from the network once they haven't been used for 3 months, and files it got from your own Mac after 1 month.
What is ~/.cargo/bin?
It holds programs installed with cargo install, and rustup puts its commands there too. Deleting it removes those tools, and possibly cargo itself.
Why does Rust use more space than ~/.cargo shows?
Builds go into each project's target folder, and toolchains live in ~/.rustup. Either can be bigger than the Cargo home.