Skip to content
Tutorials Center
My learning

Topics

Rust Reference ยท Tools

cargo install

Reference for cargo install: build and install command-line tools from crates.io, Git or a local path, choose the install root and update or uninstall them.

cargo install downloads a crate that contains a binary target, compiles it in release mode and copies the executable into Cargo's bin directory (by default ~/.cargo/bin, which rustup adds to your PATH). It is how most Rust command-line tools, such as ripgrep, cargo-audit or cargo-watch, are distributed.

It builds from source on your machine, so installs take a while but need no pre-built downloads. Any binary in PATH named cargo-xyz also becomes available as the subcommand cargo xyz. This page is a read-only command reference; the examples model what such a tool's main typically does.

Terminal
$ cargo install ripgrep
$ cargo install --path .
$ cargo install --list

Try it

Rust A tiny command-line tool

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with io::stdin().read_line()), it gets the next line from this box.

Rust Subcommand names

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with io::stdin().read_line()), it gets the next line from this box.

Syntax

Terminal
cargo install [options] [<crate>[@<version>]...]
cargo uninstall <crate>
Name Description
--path <dir> Install from a local project; with no crate name, --path . installs the current one.
--git <url> Install from a Git repository (add --branch, --tag or --rev).
--locked Use the crate's Cargo.lock instead of resolving newer dependencies. Recommended.
--force, -f Reinstall even if already installed; this is also how you upgrade.
--root <dir> Install under <dir>/bin instead of the default.
--features, --bin name Select features or one binary of a multi-binary crate.
--list Show installed crates and their versions.

Usage notes

  • A crate with only a library target cannot be installed. Use cargo add for libraries.
  • Without --locked, Cargo may pick newer dependency versions than the author tested. If an install fails to compile, try --locked.
  • cargo install has no built-in update-all command; rerun it per crate (or use a helper such as cargo-update).
  • Installs happen in a temporary target directory, so they do not touch your project's target/.
  • The plain command always compiles from source; community tools such as cargo-binstall download pre-built binaries when the author publishes them.
  • Set CARGO_HOME to move the whole Cargo directory, including bin.
  • Only install crates you trust: a build script runs arbitrary code on your machine.