1.8 KiB
Installing Binaries with cargo install
This is a commnad that allows you to install and use binary crates locally.
This is not a replacement for system packages.
It should be instead intended to be a convenient way for Rust devs to install tools that others have shared on crates.io
Note that you can only install packages that have binary targets
A binary target is the runnable program that is created if the crate has a src/main.rs file or anthoer file specified as a binary.
This is unlike a binary target that isnt unnable on its own but is suitable for including within other programs.
Usucally crates have information in the README file about whether a crate is a library, has a binary target, or both.
All binaries installed with cargo install
are saved in the installation root's bin folder.
If you installed Rust using rustup.rs and dont have any custom configs.
This file would be $HOME/.cargo/bin.
To be able to run programs you installed with cargo install
, you must ensure that this directory is in your $PATH
For example to install ripgrep
(Rust's implementation of the grep
tool) which searches files.
To install this run the following
$ cargo install ripgrep
Updating crates.io index
Downloaded ripgrep v13.0.0
Downloaded 1 crate (243.3 KB) in 0.88s
Installing ripgrep v13.0.0
--snip--
Compiling ripgrep v13.0.0
Finished `release` profile [optimized + debuginfo] target(s) in 10.64s
Installing ~/.cargo/bin/rg
Installed package `ripgrep v13.0.0` (executable `rg`)
The second last line of shows the location and the name of the installed binary.
In the case of ripgrep
is rg
.
As long as the install directory is in the $PATH
, you can then run rg --help
.
Then you can start using a faster, rustier tool for searching files!