LinuxCommandLibrary

cargo-install

Install Rust crates as executables

TLDR

Install a package from (the version is optional - latest by default)

$ cargo install [package]@[version]
copy

Install a package from the specified Git repository
$ cargo install --git [repo_url]
copy

Build from the specified branch/tag/commit when installing from a Git repository
$ cargo install --git [repo_url] --[branch|tag|rev] [branch_name|tag|commit_hash]
copy

Install a package from a local directory
$ cargo install --path [path/to/package]
copy

List all installed packages and their versions
$ cargo install --list
copy

SYNOPSIS

cargo install [-h | --help] [-V | --version] [--dry-run] [--path <PATH>] [--git <URL>] [--root <DIR>] [--force] [<CRATES>...]...

PARAMETERS

--bin <NAME>
    Install only the specified binary (if multiple available)

--bins
    Install all binaries in the package

--example <NAME>
    Install the specified example binary

--examples
    Install all example binaries

--force
    Overwrite existing installation

--git <URL>
    Install from Git repository

--branch <BRANCH>
    Git branch to use

--tag <TAG>
    Git tag to use

--rev <REV>
    Specific Git revision

--path <PATH>
    Install from local path

--registry <REGISTRY>
    Use alternate registry (default: crates.io)

--root <DIR>
    Custom installation root directory

--locked
    Use Cargo.lock for reproducible build

--offline
    Work offline using cached dependencies

--dry-run
    Simulate installation without changes

--no-track
    Don't track the package in installed registry

--target <TRIPLE>
    Install for specific target triple

-j, --jobs <N>
    Number of parallel jobs

-v
    Verbose output

--config <KEY=VAL>
    Override config value

DESCRIPTION

The cargo install command is part of Cargo, Rust's build system and package manager. It downloads, compiles, and installs binaries from crates.io (Rust's central package registry) or other sources like Git repositories or local paths into a directory typically $HOME/.cargo/bin, which should be added to your PATH for easy access.

It resolves dependencies automatically, ensuring reproducible builds when using --locked. Ideal for installing command-line tools and utilities without needing a full project workspace. For example, cargo install ripgrep fetches and installs the ripgrep binary.

Supports multiple crates in one invocation, Git sources with branches/tags/revisions, and local crates. By default, it tracks installed packages to allow easy updates or removals via cargo uninstall. Use --force to overwrite existing installations. Requires a Rust toolchain installed via rustup.

Installation is cross-compile friendly with --target, and offline mode works if dependencies are cached.

CAVEATS

Requires Rust toolchain via rustup; installs to $HOME/.cargo/bin by default (add to PATH); may fail if binary name conflicts; Git installs track remotes loosely; large crates can take time to compile.

DEFAULT LOCATION

Binaries installed to $CARGO_HOME/bin (defaults to $HOME/.cargo/bin); ensure in PATH.

UPDATING PACKAGES

Re-run cargo install <crate> to update; use --force if needed.

HISTORY

Introduced in Cargo 0.0.1 (2014) with Rust's initial package manager; evolved alongside Rust from Mozilla's Servo project; now maintained by Rust Project; major updates with Cargo 1.0 (2017) stabilized flags like --locked.

SEE ALSO

Copied to clipboard