]>
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 |
2c00a5a8 XL |
6 | [crates.io](https://crates.io)<!-- ignore -->. You can only install packages |
7 | that have binary targets. A binary target is the runnable program that is | |
8 | created if the crate has a *src/main.rs* file or another file specified as a | |
9 | binary, as opposed to a library target that isn’t runnable on its own but is | |
10 | suitable for including within other programs. Usually, crates have information | |
11 | in the *README* file about whether a crate is a library, has a binary target, | |
12 | or both. | |
cc61c64b | 13 | |
2c00a5a8 XL |
14 | All binaries installed with `cargo install` are stored in the installation |
15 | root’s *bin* folder. If you installed Rust using *rustup.rs* and don’t have any | |
16 | custom configurations, this directory will be *$HOME/.cargo/bin*. Ensure that | |
17 | directory is in your `$PATH` to be able to run programs you’ve installed with | |
18 | `cargo install`. | |
3b2f2976 | 19 | |
2c00a5a8 XL |
20 | For example, in Chapter 12 we mentioned that there’s a Rust implementation of |
21 | the `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 | |
26 | Updating 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 | ||
34 | The last line of the output shows the location and the name of the installed | |
3b2f2976 | 35 | binary, which in the case of `ripgrep` is `rg`. As long as the installation |
2c00a5a8 XL |
36 | directory is in your `$PATH`, as mentioned previously, you can then run `rg` |
37 | `--help` and start using a faster, rustier tool for searching files! |