]> git.proxmox.com Git - rustc.git/blame - src/doc/book/second-edition/src/ch14-04-installing-binaries.md
New upstream version 1.25.0+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
2c00a5a8
XL
6[crates.io](https://crates.io)<!-- ignore -->. You can only install packages
7that have binary targets. A binary target is the runnable program that is
8created if the crate has a *src/main.rs* file or another file specified as a
9binary, as opposed to a library target that isn’t runnable on its own but is
10suitable for including within other programs. Usually, crates have information
11in the *README* file about whether a crate is a library, has a binary target,
12or both.
cc61c64b 13
2c00a5a8
XL
14All binaries installed with `cargo install` are stored in the installation
15root’s *bin* folder. If you installed Rust using *rustup.rs* and don’t have any
16custom configurations, this directory will be *$HOME/.cargo/bin*. Ensure that
17directory is in your `$PATH` to be able to run programs you’ve installed with
18`cargo install`.
3b2f2976 19
2c00a5a8
XL
20For example, in Chapter 12 we mentioned that there’s a Rust implementation of
21the `grep` tool called `ripgrep` for searching files. If we want to install
22`ripgrep`, we can run the following:
cc61c64b
XL
23
24```text
25$ cargo install ripgrep
26Updating registry `https://github.com/rust-lang/crates.io-index`
27 Downloading ripgrep v0.3.2
ff7c6d11 28 --snip--
cc61c64b
XL
29 Compiling ripgrep v0.3.2
30 Finished release [optimized + debuginfo] target(s) in 97.91 secs
31 Installing ~/.cargo/bin/rg
32```
33
34The last line of the output shows the location and the name of the installed
3b2f2976 35binary, which in the case of `ripgrep` is `rg`. As long as the installation
2c00a5a8
XL
36directory is in your `$PATH`, as mentioned previously, you can then run `rg`
37`--help` and start using a faster, rustier tool for searching files!