49 lines
2.6 KiB
HTML
49 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>Installing Binaries with cargo install</title>
|
||
</head>
|
||
<body>
|
||
<!-- Old headings. Do not remove or links may break. -->
|
||
<p><a id="installing-binaries-from-cratesio-with-cargo-install"></a></p>
|
||
<h2 id="installing-binaries-with-cargo-install"><a class="header" href="#installing-binaries-with-cargo-install">Installing Binaries with <code>cargo install</code></a></h2>
|
||
<p>The <code>cargo install</code> command allows you to install and use binary crates
|
||
locally. This isn’t intended to replace system packages; it’s meant to be a
|
||
convenient way for Rust developers to install tools that others have shared on
|
||
<a href="https://crates.io/">crates.io</a><!-- ignore -->. Note that you can only install
|
||
packages that have binary targets. A <em>binary target</em> is the runnable program
|
||
that is created if the crate has a <em>src/main.rs</em> file or another file specified
|
||
as a binary, as opposed to a library target that isn’t runnable on its own but
|
||
is suitable for including within other programs. Usually, crates have
|
||
information in the README file about whether a crate is a library, has a
|
||
binary target, or both.</p>
|
||
<p>All binaries installed with <code>cargo install</code> are stored in the installation
|
||
root’s <em>bin</em> folder. If you installed Rust using <em>rustup.rs</em> and don’t have any
|
||
custom configurations, this directory will be <em>$HOME/.cargo/bin</em>. Ensure that
|
||
this directory is in your <code>$PATH</code> to be able to run programs you’ve installed
|
||
with <code>cargo install</code>.</p>
|
||
<p>For example, in Chapter 12 we mentioned that there’s a Rust implementation of
|
||
the <code>grep</code> tool called <code>ripgrep</code> for searching files. To install <code>ripgrep</code>, we
|
||
can run the following:</p>
|
||
<!-- manual-regeneration
|
||
cargo install something you don't have, copy relevant output below
|
||
-->
|
||
<pre><code class="language-console">$ cargo install ripgrep
|
||
Updating crates.io index
|
||
Downloaded ripgrep v14.1.1
|
||
Downloaded 1 crate (213.6 KB) in 0.40s
|
||
Installing ripgrep v14.1.1
|
||
--snip--
|
||
Compiling grep v0.3.2
|
||
Finished `release` profile [optimized + debuginfo] target(s) in 6.73s
|
||
Installing ~/.cargo/bin/rg
|
||
Installed package `ripgrep v14.1.1` (executable `rg`)
|
||
</code></pre>
|
||
<p>The second-to-last line of the output shows the location and the name of the
|
||
installed binary, which in the case of <code>ripgrep</code> is <code>rg</code>. As long as the
|
||
installation directory is in your <code>$PATH</code>, as mentioned previously, you can
|
||
then run <code>rg --help</code> and start using a faster, Rustier tool for searching files!</p>
|
||
</body>
|
||
</html>
|