On my Windows 10 machine it's 3.5GG. What is it storing? How can I trim it down?
Asked
Active
Viewed 5,025 times
10
-
2My intermediate directory of our C++ build has about 150GB ... so 3.5 doesn't seem to bad for whatever build system :-) – Martin Ba Sep 25 '20 at 12:11
-
1@MartinBa That includes object files and debugging information for them. `.cargo` does not include build artifacts for a given project. – Acorn Sep 25 '20 at 12:19
1 Answers
13
It is storing all the downloaded crates you have used, their binaries, the index of registries, etc. It is going to take a lot of space and will keep increasing.
You can safely remove .cargo/registry/
(if you remove the entire folder, you will lose installed binaries and your Cargo configuration if you had one). Afterwards, everything you use again will be downloaded and it will start growing back. It is a common way of getting rid of very old dependencies you are not using anymore.

Acorn
- 24,970
- 5
- 40
- 69
-
It also contains every version of the crate you've downloaded btw. – Optimistic Peach Sep 25 '20 at 12:12
-
3I definitely wouldn't remove anything but `~/.cargo/registry/` (assuming Windows has the same folder hierarchy as Linux). The rest are the binaries you've installed (you probably don't want to remove those) and the configuration (that's tiny). The registry is the one big thing, it can safely be removed, and will be reconstructed as needed. – mcarton Sep 25 '20 at 12:12
-
I was under the impression downloaded crates went into the target directory of each project? – Pablo Tato Ramos Sep 25 '20 at 12:12
-
4@PabloTatoRamos the compiled artifacts do, the sources are shared. The reason is that sources are the same for every project, while artifacts might be different due to different compiler options, different features sets, etc. – mcarton Sep 25 '20 at 12:15
-
-
@PabloTatoRamos they are copied into the target directory (or perhaps they're complied in place but the target directory for their output is the target directory for your crate, I'm not 100% sure), however the actual code for them is stored in `~/.cargo`. This would actually save some space if you have multiple projects which use the same dependencies. – Optimistic Peach Sep 25 '20 at 12:17
-
`.cargo/registry` has 3 subdirectories, I'd there's probably no need to remove `index` (which would be the cargo index) and `cache` is just the crate data so may or may not be useful to clean up. – Masklinn Sep 25 '20 at 12:46
-
This might be a noob question but if I vendor all my dependencies into my project folder first, and then delete the registry folder, can I build the project totally offline thereafter? – Keyboard Penman Apr 20 '23 at 06:15