52

I've installed several CLI tools using cargo install (for instance, ripgrep). How do I see a list of all the crates I've downloaded using cargo install? Sort of like apt list --installed but for cargo?

almel
  • 7,178
  • 13
  • 45
  • 58

3 Answers3

65

The command line

cargo help install

produces detailed help information. Among others, it lists common EXAMPLES, e.g.

  1. View the list of installed packages:

    cargo install --list
    

This lists all installed packages alongside their versions and the collection of binaries contained. Doing this is superior to other proposed solutions as packages can contain multiple binaries (e.g. cargo-edit) or have a binary name that doesn't match the crate name (such as ripgrep).

Just be careful not to type cargo install list as that is trying to install the list package, which thankfully errors out at the time of writing (as opposed to installing a rogue binary).

IInspectable
  • 46,945
  • 8
  • 85
  • 181
8

ls ~/.cargo/bin/

The binary files are stored here, so listing all the files in this directory will give you all the global cargo crates you've installed.

almel
  • 7,178
  • 13
  • 45
  • 58
  • 4
    The installed binary name doesn't necessarily match the package name, e.g. `cargo install cargo-edit` gives you `cargo-add` and `cargo-rm`. – gib Oct 31 '22 at 11:09
0

If you want to manipulate the list shown by cargo install --list, then please check:

cat $CARGO_HOME/.crates.toml
cat $CARGO_HOME/.crates2.json | jq .

Please note that .crates2.json is in json format.

To list out the installed package names you could run:

cat $CARGO_HOME/.crates2.json | jq -r '.installs | keys[] | split(" ")[0]'
gib
  • 1,951
  • 1
  • 21
  • 24
Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87
  • Helpful answer, but for me the path was `$CARGO_HOME/.crates2.json` (not inside the `bin` directory). – gib Oct 31 '22 at 11:08