]>
Commit | Line | Data |
---|---|---|
cc61c64b XL |
1 | ## Installing Binaries from Crates.io with `cargo install` |
2 | ||
3 | The `cargo install` command allows you to install and use binary crates | |
3b2f2976 | 4 | locally. This isn’t intended to replace system packages; it’s meant to be a |
cc61c64b | 5 | convenient way for Rust developers to install tools that others have shared on |
3b2f2976 XL |
6 | crates.io. Only packages that have binary targets can be installed. A binary |
7 | target 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 | |
9 | target that isn’t runnable on its own but is suitable for including within | |
10 | other programs. Usually, crates have information in the *README* file about | |
11 | whether a crate is a library, has a binary target, or both. | |
cc61c64b | 12 | |
3b2f2976 XL |
13 | All binaries from `cargo install` are put into the installation root’s *bin* |
14 | folder. If you installed Rust using *rustup.rs* and don’t have any custom | |
ea8adc8c XL |
15 | configurations, this will be `$HOME/.cargo/bin`. Ensure that directory is in |
16 | your `$PATH` to be able to run programs you’ve gotten through `cargo install`. | |
3b2f2976 XL |
17 | |
18 | For example, we mentioned in Chapter 12 that there’s a Rust implementation of | |
cc61c64b XL |
19 | the `grep` tool for searching files called `ripgrep`. If we want to install |
20 | `ripgrep`, we can run: | |
21 | ||
22 | ```text | |
23 | $ cargo install ripgrep | |
24 | Updating 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 | ||
32 | The last line of the output shows the location and the name of the installed | |
3b2f2976 XL |
33 | binary, which in the case of `ripgrep` is `rg`. As long as the installation |
34 | directory is in your `$PATH` as mentioned above, you can then run `rg --help` | |
35 | and start using a faster, rustier tool for searching files! |