78

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?

4 Answers 4

96

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).

11

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.

1
  • 5
    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
    Commented Oct 31, 2022 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]'
1
  • Helpful answer, but for me the path was $CARGO_HOME/.crates2.json (not inside the bin directory).
    – gib
    Commented Oct 31, 2022 at 11:08
0

A bit late to the party here but I recently needed to install all the packages on one machine on another so I came up with this little sequence

cargo install --list | awk '/^\w/ {print $1}' | tr '\n' ' ' | ssh [yourremote] "xargs cargo install"

If you just need the package names cargo install --list | awk '/^\w/ {print $1}' will get you just the package names.

Not the answer you're looking for? Browse other questions tagged or ask your own question.