]> git.proxmox.com Git - rustc.git/blame - src/doc/book/second-edition/src/ch14-04-installing-binaries.md
New upstream version 1.22.1+dfsg1
[rustc.git] / src / doc / book / second-edition / src / ch14-04-installing-binaries.md
CommitLineData
cc61c64b
XL
1## Installing Binaries from Crates.io with `cargo install`
2
3The `cargo install` command allows you to install and use binary crates
3b2f2976 4locally. This isn’t intended to replace system packages; it’s meant to be a
cc61c64b 5convenient way for Rust developers to install tools that others have shared on
3b2f2976
XL
6crates.io. Only packages that have binary targets can be installed. A binary
7target is the runnable program that gets created if the crate has a
8*src/main.rs* or another file specified as a binary, as opposed to a library
9target that isn’t runnable on its own but is suitable for including within
10other programs. Usually, crates have information in the *README* file about
11whether a crate is a library, has a binary target, or both.
cc61c64b 12
3b2f2976
XL
13All binaries from `cargo install` are put into the installation root’s *bin*
14folder. If you installed Rust using *rustup.rs* and don’t have any custom
ea8adc8c
XL
15configurations, this will be `$HOME/.cargo/bin`. Ensure that directory is in
16your `$PATH` to be able to run programs you’ve gotten through `cargo install`.
3b2f2976
XL
17
18For example, we mentioned in Chapter 12 that there’s a Rust implementation of
cc61c64b
XL
19the `grep` tool for searching files called `ripgrep`. If we want to install
20`ripgrep`, we can run:
21
22```text
23$ cargo install ripgrep
24Updating registry `https://github.com/rust-lang/crates.io-index`
25 Downloading ripgrep v0.3.2
26 ...snip...
27 Compiling ripgrep v0.3.2
28 Finished release [optimized + debuginfo] target(s) in 97.91 secs
29 Installing ~/.cargo/bin/rg
30```
31
32The last line of the output shows the location and the name of the installed
3b2f2976
XL
33binary, which in the case of `ripgrep` is `rg`. As long as the installation
34directory is in your `$PATH` as mentioned above, you can then run `rg --help`
35and start using a faster, rustier tool for searching files!