cargo clean ~/.cargo

Created on 13 Nov 2016  ·  9Comments  ·  Source: rust-lang/cargo

Would it be possible to have a cargo clean command for all the downloaded deps in ~/.cargo? I'm currently using a small HDD (Chromebook) and would like to cleanup whatever I can, included sources and the local index (not sure it's in ~/.cargo).

A-caching C-feature-request

Most helpful comment

This is a sorta old bug, it seems real weird that this is still not a supported feature of cargo. Most package managers have a "clear cache files" command. I feel like I shouldn't have had to search google to find a github issue with scary "manually delete these files" instructions, I should have been able to find how to do it just by typing "cargo help"…

All 9 comments

Also, I'm not sure what I can actually safely delete.

In general it's always safe to completely rm -rf ~/.cargo (unless you've got your own data there like config, installed crates, rustup, etc). Seems fine to have something like cargo clean --global though!

FWIW, it looks like you can safely delete ~/.cargo/registry and the binaries under ~/.cargo/bin will keep working. At least they did when I moved the registry directory elsewhere.

Hey Florian - just ran into this - 👍 would have expected this to be built in.

I made a small plugin that prints cache size and can clean out different parts of it, feel free to try it out:
https://github.com/matthiaskrgr/cargo-cache

rm -rf ~/.cargo blows away your rustup binaries in PATH, I do not recommend.

The following command in addition to what has been mention may help saving disk space.
Go into the folder containing all your rust projects:

find `pwd` -maxdepth 5 -type d -name 'target' | grep -v supercurrentproject | xargs rm -rf

It wont do anything a cargo build can fix again.

This is a sorta old bug, it seems real weird that this is still not a supported feature of cargo. Most package managers have a "clear cache files" command. I feel like I shouldn't have had to search google to find a github issue with scary "manually delete these files" instructions, I should have been able to find how to do it just by typing "cargo help"…

For anyone interested I have released cargo-cache on crates.io a few months ago, cargo install cargo-cache to install.

rm -rf ~/.cargo blows away your rustup binaries in PATH, I do not recommend.

cargo-cache can remove dirs selectively via --remove-dir git-repos,registry-sources (this for example will only remove checkouts of cloned git repos but not touch the original repos and also remove unpacked crate sources).

To be extra sure you can perform a --dry-run first which will tell you the directory paths that would be removed.

If you have any additional ideas or feature requests, I would be glad to hear them. :)

Was this page helpful?
0 / 5 - 0 ratings