]>
Commit | Line | Data |
---|---|---|
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 | |
6 | The `cargo install` command allows you to install and use binary crates | |
7 | locally. This isn’t intended to replace system packages; it’s meant to be a | |
8 | convenient 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 |
10 | packages that have binary targets. A *binary target* is the runnable program |
11 | that is created if the crate has a *src/main.rs* file or another file specified | |
12 | as a binary, as opposed to a library target that isn’t runnable on its own but | |
13 | is suitable for including within other programs. Usually, crates have | |
14 | information in the *README* file about whether a crate is a library, has a | |
15 | binary target, or both. | |
16 | ||
17 | All binaries installed with `cargo install` are stored in the installation | |
18 | root’s *bin* folder. If you installed Rust using *rustup.rs* and don’t have any | |
19 | custom configurations, this directory will be *$HOME/.cargo/bin*. Ensure that | |
20 | directory is in your `$PATH` to be able to run programs you’ve installed with | |
21 | `cargo install`. | |
22 | ||
23 | For example, in Chapter 12 we mentioned that there’s a Rust implementation of | |
04454e1e FG |
24 | the `grep` tool called `ripgrep` for searching files. To install `ripgrep`, we |
25 | can run the following: | |
13cf67c4 | 26 | |
74b04a01 XL |
27 | <!-- manual-regeneration |
28 | cargo 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 |
44 | The second-to-last line of the output shows the location and the name of the |
45 | installed binary, which in the case of `ripgrep` is `rg`. As long as the | |
46 | installation directory is in your `$PATH`, as mentioned previously, you can | |
47 | then run `rg --help` and start using a faster, rustier tool for searching files! |