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 [OPTIONS] CRATE
cargo install [OPTIONS] --path PATH
cargo install [OPTIONS] --git URL [CRATE]

PARAMETERS

CRATE
    The name of the crate to install from crates.io.

--version VERSION
    Installs a specific version of the crate.

--path PATH
    Installs a crate from a local path.

--git URL
    Installs a crate from a Git repository.

--force, -f
    Forces reinstallation even if the crate is already installed.

--root DIR
    Specifies the installation root directory.

--target TRIPLE
    Builds for a specific target architecture.

--profile NAME
    Builds with a specific profile (e.g., release or debug).

--features FEATURES
    Activates specified features.

--all-features
    Activates all available features.

--no-default-features
    Does not activate default features.

--debug
    Builds with debug information (not optimized).

--offline
    Works offline, without accessing the network.

--bins
    Only install binaries listed in the package.

--examples
    Only install examples listed in the package.

DESCRIPTION

cargo install is a Cargo subcommand used to compile and install Rust executables. It fetches the specified crate from crates.io (Rust's package registry), a Git repository, or a local path, then compiles its binary targets and places them into a specified installation directory, typically ~/.cargo/bin. This command is essential for distributing and using command-line tools written in Rust, making them accessible via your system's PATH after installation. It handles dependency resolution and compilation, similar to cargo build, but specifically for installation. If the binary already exists, it will be updated.

CAVEATS

For binaries installed by cargo install to be directly executable from the command line, the installation directory (typically ~/.cargo/bin) must be included in your system's PATH environment variable. If not, you'll need to specify the full path to run them. Compilation can be time-consuming, especially for projects with many dependencies. Conflicts can occur if you try to install a binary with the same name as an existing system command, requiring the --force flag for an overwrite.

DEFAULT INSTALLATION LOCATION

By default, cargo install places compiled binaries into $HOME/.cargo/bin. This directory is usually added to your system's PATH by the rustup installer during initial setup, ensuring that installed binaries are immediately executable from any terminal location. If this is not the case, you may need to manually add $HOME/.cargo/bin to your PATH in your shell's configuration file (e.g., .bashrc, .zshrc).

HISTORY

cargo install has been a core part of the Cargo tool since its early development alongside the Rust programming language. It emerged as the standard method for users to easily acquire and use command-line applications written in Rust, directly leveraging Cargo's robust dependency management and build capabilities. Its integration into the Cargo ecosystem made it a fundamental component for the distribution and adoption of Rust-based tooling, becoming ubiquitous for developers publishing their command-line utilities.

SEE ALSO

cargo(1): The Rust package manager and build tool., rustup(1): The Rust toolchain installer and manager., rustc(1): The Rust compiler., env(1): Used to manage environment variables like PATH.

Copied to clipboard