Cargo registry src keeps growing

My $HOME/.cargo/registry/src is up to 200MB now and keeps growing. This is because I'm trying various new crates as I learn Rust.

I use cargo clean for the little apps I try out, but what I'd like to do is get rid of all the stuff in $HOME/.cargo/registry/src that none of my apps use.

Is it safe to do rm -rf on this directory & trust that cargo will redownload anything it needs the next time I build something?

Added:
What would help me (but don't know how possible) would be:

cargo clean --registry

to completely clear out the registry so that everything gets downloaded fresh as needed, and

cargo clean -r or cargo clean --recursive

to do the same as cargo clean but working recursively. The use case for this is if you have a directory of many separate examples (which is my situation as a beginner trying lots of little apps).

1 Like

Perhaps cargo needs a new command (or new alternative cleaning method) to clean its databases.

It is safe to delete .cargo/registry, yeah. It would be nice to have a command to do it for you though!

1 Like

It would be nice if there was a way to just clean out old crates that you're no longer using from the cache. Maybe Cargo could record the paths to any Cargo.lock it interacts with in a file in the cache during normal usage, then a command like cargo cache clean looks at the entire list of referenced crates from those Cargo.lock files (ignoring any lock files that don't exist) and deletes all unreferenced crates from the cache. Something like cargo cache clean --all could then the lock files and just delete all crates from the cache.