How to clear the Cargo cache?
Asked Answered
S

2

66

When I run cargo build, various libs get stored within the folder /usr/local/lib/rustlib/.

What is the correct way to clear these libs? I could rm these files manually, but would that be the right thing to do? I noticed that /usr/local/lib/rustlib/manifest is a file containing a list of the fill file paths of all the libs, and hence might be breaking something if I remove these files manually.

Sulfanilamide answered 1/8, 2014 at 4:34 Comment(0)
V
35

I believe that manifest file is just for the built-in libraries, i.e. those distributed with rustc. cargo itself stores things in ~/.cargo (for the moment), if you do wish to just remove all the libraries then deleting that directory won't break anything.

If you're just wanting cargo to rebuild/update dependencies you can run cargo update.

Vaticinal answered 1/8, 2014 at 5:1 Comment(3)
Thanks for pointing me to ~/.cargo, that is what I was looking for!Sulfanilamide
keep the bin folder if you don't want to reinstall all that cool Rust tools you've installed )Manipular
In particular, by default this will remove the cargo executable itself too.Francinefrancis
K
73

Install and run cargo-cache to clear the cache in the ~/.cargo folder:

cargo install cargo-cache
cargo cache -a
Kentish answered 19/8, 2021 at 21:27 Comment(6)
error caused by "feature resolver is required" :sad_face:Olnek
error: no such subcommand: cacheSizzler
@Sizzler did you remember to install cargo-cache first?Kentish
If you no longer have any need of any of the cargo crates, such as just wanting to compile a project and then freeing up the space afterward, the command to use is cargo-cache --remove-dir all (or cargo-cache -r all for short).Torras
I found this useful when using dependencies with versions that cargo does not support. For example, Cargo will not download the correct dependency when you switch a dependency from 1.2.0-dev.1 to 1.2.0-dev.2. It doesn't respect semver "pre-release versions" (Cargo doesn't document this) semver "build metadata" (documented).Earl
I ran into an issue with the cache that made me unable to install/build cargo-cache normally. What worked for me was to just update rust (rustup update) so it wouldn't use cached builds made with previous versions of rustc. This was only possible since I did not need to use a specific version of rustc, but it did help give me the peace of mind that I was not going to break something by manually deleting files. Afterwards, I was able to install cargo-cache and have it do a full cache reset.Merilyn
V
35

I believe that manifest file is just for the built-in libraries, i.e. those distributed with rustc. cargo itself stores things in ~/.cargo (for the moment), if you do wish to just remove all the libraries then deleting that directory won't break anything.

If you're just wanting cargo to rebuild/update dependencies you can run cargo update.

Vaticinal answered 1/8, 2014 at 5:1 Comment(3)
Thanks for pointing me to ~/.cargo, that is what I was looking for!Sulfanilamide
keep the bin folder if you don't want to reinstall all that cool Rust tools you've installed )Manipular
In particular, by default this will remove the cargo executable itself too.Francinefrancis

© 2022 - 2024 — McMap. All rights reserved.