]> git.proxmox.com Git - rustc.git/blame - src/doc/book/src/ch14-04-installing-binaries.md
New upstream version 1.66.0+dfsg1
[rustc.git] / src / doc / book / src / ch14-04-installing-binaries.md
CommitLineData
04454e1e
FG
1<!-- Old link, do not remove -->
2<a id="installing-binaries-from-cratesio-with-cargo-install"></a>
3
4## Installing Binaries with `cargo install`
13cf67c4
XL
5
6The `cargo install` command allows you to install and use binary crates
7locally. This isn’t intended to replace system packages; it’s meant to be a
8convenient way for Rust developers to install tools that others have shared on
dc9dc135 9[crates.io](https://crates.io/)<!-- ignore -->. Note that you can only install
13cf67c4
XL
10packages that have binary targets. A *binary target* is the runnable program
11that is created if the crate has a *src/main.rs* file or another file specified
12as a binary, as opposed to a library target that isn’t runnable on its own but
13is suitable for including within other programs. Usually, crates have
14information in the *README* file about whether a crate is a library, has a
15binary target, or both.
16
17All binaries installed with `cargo install` are stored in the installation
18root’s *bin* folder. If you installed Rust using *rustup.rs* and don’t have any
19custom configurations, this directory will be *$HOME/.cargo/bin*. Ensure that
20directory is in your `$PATH` to be able to run programs you’ve installed with
21`cargo install`.
22
23For example, in Chapter 12 we mentioned that there’s a Rust implementation of
04454e1e
FG
24the `grep` tool called `ripgrep` for searching files. To install `ripgrep`, we
25can run the following:
13cf67c4 26
74b04a01
XL
27<!-- manual-regeneration
28cargo install something you don't have, copy relevant output below
29-->
30
f035d41b 31```console
13cf67c4 32$ cargo install ripgrep
74b04a01 33 Updating crates.io index
2b03887a 34 Downloaded ripgrep v13.0.0
74b04a01 35 Downloaded 1 crate (243.3 KB) in 0.88s
2b03887a 36 Installing ripgrep v13.0.0
74b04a01 37--snip--
2b03887a 38 Compiling ripgrep v13.0.0
fc512014 39 Finished release [optimized + debuginfo] target(s) in 3m 10s
13cf67c4 40 Installing ~/.cargo/bin/rg
2b03887a 41 Installed package `ripgrep v13.0.0` (executable `rg`)
13cf67c4
XL
42```
43
74b04a01
XL
44The second-to-last line of the output shows the location and the name of the
45installed binary, which in the case of `ripgrep` is `rg`. As long as the
46installation directory is in your `$PATH`, as mentioned previously, you can
47then run `rg --help` and start using a faster, rustier tool for searching files!