Files
docs-rust/ch14/ch14-04-installing-binaries.html
2026-06-22 21:27:36 +05:30

49 lines
2.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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 isnt intended to replace system packages; its 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 isnt 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
roots <em>bin</em> folder. If you installed Rust using <em>rustup.rs</em> and dont 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 youve installed
with <code>cargo install</code>.</p>
<p>For example, in Chapter 12 we mentioned that theres 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>