CARGO-INSTALL(1)
โจ NAME โจ
okay bestie gather round ๐ it's cargo-install โ the one that builds a Rust binary and installs it. That's the whole plot. This page lives in the General Commands Manual, and honestly? Iconic.
๐ฆ SYNOPSIS ๐ฆ
cargo install [options] crate[@version]โฆ
cargo install [options] --path path
cargo install [options] --git url [crateโฆ]
cargo install [options] --list
๐ DESCRIPTION ๐
So this command is the manager of Cargo's local lil set of installed binary crates ๐. Only packages that actually have an executable [[bin]] or [[example]] target can be installed, and every single executable lands in the installation root's bin folder. And by default? Only binaries get installed. Not examples. Examples are not invited to the default party.
Now โ where even is the installation root? It's figured out in this exact order of precedence, first hit wins:
- the
--rootoption - the
CARGO_INSTALL_ROOTenvironment variable - the
install.rootCargo config value (https://doc.rust-lang.org/cargo/reference/config.html) - the
CARGO_HOMEenvironment variable $HOME/.cargo
There are multiple sources a crate can come from, and the default source location is crates.io โ but --git, --path, and --registry can switch that up. If the source contains more than one package (like crates.io does, or a git repo with a bunch of crates in it) then the crate argument is required to say which crate should be installed. No guessing, bestie.
Crates from crates.io can optionally say which version they want via the --version flags, and same energy for packages from git repositories โ those can optionally specify the branch, tag, or revision that should be installed. If a crate has multiple binaries, --bin lets you selectively install just one of them, and if you'd rather install examples, the --example argument is right there for you.
Already got the package installed? Cargo will reinstall it if the installed version doesn't appear to be up-to-date. And if any of these change, Cargo reinstalls:
- The package version and source.
- The set of binary names installed.
- The chosen features.
- The profile (
--profile). - The target (
--target).
Installing with --path will always build and install, unless there are conflicting binaries from another package. And the --force flag may be used to force Cargo to always reinstall the package. Periodt.
If the source is crates.io or --git then by default the crate gets built in a temporary target directory. To avoid that whole situation, you can specify the target directory by setting the CARGO_TARGET_DIR environment variable to a path. This is especially useful for caching build artifacts on continuous integration systems, ngl, that's the good stuff ๐ซถ.
๐ Dealing with the Lockfile ๐
By default, the Cargo.lock file that ships with the package is ignored ๐. Which means Cargo recomputes which versions of dependencies to use โ possibly pulling newer versions that got released after the package was published. The --locked flag can force Cargo to use the packaged Cargo.lock file if it's available. This may be useful for ensuring reproducible builds, so you use the exact same set of dependencies that were available when the package was published. It may also be useful if a newer version of a dependency got published that no longer builds on your system, or has other problems. The downside to --locked is that you will not receive any fixes or updates to any dependency. And note: Cargo did not start publishing Cargo.lock files until version 1.37, which means packages published with prior versions will not have a Cargo.lock file available. Rip to the old ones ๐.
๐งญ Configuration Discovery ๐งญ
This command operates on system or user level, not project level. Which means the local configuration discovery (https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure) is ignored. Instead, configuration discovery begins at $CARGO_HOME/config.toml. But โ if the package is installed with --path $PATH, the local configuration will be used, beginning discovery at $PATH/.cargo/config.toml.
๐ OPTIONS ๐
Install Options
--vers version,--version versionโ Specify a version to install. This may be a version requirement (https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html), like~1.2, to have Cargo select the newest version from the given requirement. If the version does not have a requirement operator (such as^or~), then it must be in the formMAJOR.MINOR.PATCH, and will install exactly that version โ it is not treated as a caret requirement like Cargo dependencies are.--git urlโ Git URL to install the specified crate from.--branch branchโ Branch to use when installing from git.--tag tagโ Tag to use when installing from git.--rev shaโ Specific commit to use when installing from git.--path pathโ Filesystem path to local crate to install from.--listโ List all installed packages and their versions.-n,--dry-runโ (unstable) Perform all checks without installing.-f,--forceโ Force overwriting existing crates or binaries. This can be used if a package has installed a binary with the same name as another package. Also useful if something has changed on the system that you want to rebuild with, such as a newer version ofrustc.--no-trackโ By default, Cargo keeps track of the installed packages with a metadata file stored in the installation root directory. This flag tells Cargo not to use or create that file. With this flag, Cargo will refuse to overwrite any existing files unless the--forceflag is used. This also disables Cargo's ability to protect against multiple concurrent invocations of Cargo installing at the same time.--bin nameโฆโ Install only the specified binary.--binsโ Install all binaries. This is the default behavior.--example nameโฆโ Install only the specified example.--examplesโ Install all examples.--root dirโ Directory to install packages into.--registry registryโ Name of the registry to use. Registry names are defined in Cargo config files (https://doc.rust-lang.org/cargo/reference/config.html). If not specified, the default registry is used, which is defined by theregistry.defaultconfig key which defaults tocrates-io.--index indexโ The URL of the registry index to use.
๐ธ Feature Selection ๐ธ
The feature flags let you control which features are enabled. When no feature options are given, the default feature is activated for every selected package.
See the features documentation (https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options) for more details.
-F features,--features featuresโ Space or comma separated list of features to activate. Features of workspace members may be enabled withpackage-name/feature-namesyntax. This flag may be specified multiple times, which enables all specified features.--all-featuresโ Activate all available features of all selected packages.--no-default-featuresโ Do not activate the default feature of the selected packages.
๐ฅ Compilation Options ๐ฅ
--target tripleโ Install for the specified target architecture. The default is the host architecture. The general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>.
Possible values:
- Any supported target in
rustc --print target-list. "host-tuple", which will internally be substituted by the host's target. This can be particularly useful if you're cross-compiling some crates, and don't want to specify your host's machine as a target (for instance, an xtask in a shared project that may be worked on by many hosts).- A path to a custom target specification. See Custom Target Lookup Path (
https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path) for more information.
This may also be specified with the build.target config value (https://doc.rust-lang.org/cargo/reference/config.html).
Note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the build cache (https://doc.rust-lang.org/cargo/reference/build-cache.html) documentation for more details.
--target-dir directoryโ Directory for all generated artifacts and intermediate files. May also be specified with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig value (https://doc.rust-lang.org/cargo/reference/config.html). Defaults to a new temporary folder located in the temporary directory of the platform.
When using --path, by default it will use target directory in the workspace of the local crate unless --target-dir is specified.
--debugโ Build with the debug profile instead of the release profile. See also the--profileoption for choosing a specific profile by name.--profile nameโ Install with the given profile. See the reference (https://doc.rust-lang.org/cargo/reference/profiles.html) for more details on profiles.--timingsโ Output information how long each compilation takes, and track concurrency information over time.
A file cargo-timing.html will be written to the target/cargo-timings directory at the end of the build. An additional report with a timestamp in its filename is also written if you want to look at a previous run. These reports are suitable for human consumption only, and do not provide machine-readable timing data.
๐ Manifest Options ๐
--ignore-rust-versionโ Ignorerust-versionspecification in packages.--lockedโ Asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of the following scenarios arises:- The lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
It may be used in environments where deterministic builds are desired, such as in CI pipelines.
--offlineโ Prevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. With this flag, Cargo will attempt to proceed without the network if possible.
Beware, bestie โ this can give you different dependency resolution than online mode does. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. So if you wanna go offline on purpose, see the cargo-fetch(1) command to download dependencies before you disconnect. ๐ซถ
May also be specified with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.
--frozenโ the "do both" button โจ. Equivalent to specifying both--lockedand--offlineat once. Two vibes, one flag.
๐งฐ Miscellaneous Options ๐งฐ
-j N,--jobs Nโ Number of parallel jobs to run. May also be specified with thebuild.jobsconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to the number of logical CPUs. If negative, it sets the maximum number of parallel jobs to the number of logical CPUs plus provided value. If a string default is provided, it sets the value back to defaults. Should not be 0. ๐ซ--keep-goingโ Build as many crates in the dependency graph as possible, rather than aborting the build on the first one that fails to build.
For example if the current package depends on dependencies fails and works, one of which fails to build, cargo install -j1 may or may not build the one that succeeds (depending on which one of the two builds Cargo picked to run first), whereas cargo install -j1 --keep-going would definitely run both builds, even if the one run first fails.
ngl this is the "we don't stop, we keep going" of flags ๐
๐ Display Options ๐
-v,--verboseโ Use verbose output. May be specified twice for โvery verboseโ output which includes extra output such as dependency warnings and build script output. May also be specified with theterm.verboseconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.-q,--quietโ Do not print cargo log messages. May also be specified with theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.--color whenโ Control when colored output is used. Valid values:auto(default): Automatically detect if color support is available on the terminal.always: Always display colors.never: Never display colors.
May also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.
color my terminal like it's a main character ๐
--message-format fmtโ The output format for diagnostic messages. Can be specified multiple times and consists of comma-separated values. Valid values:human(default): Display in a human-readable text format. Conflicts withshortandjson.short: Emit shorter, human-readable text messages. Conflicts withhumanandjson.json: Emit JSON messages to stdout. See the reference <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages> for more details. Conflicts withhumanandshort.json-diagnostic-short: Ensure therenderedfield of JSON messages contains the โshortโ rendering fromrustc. Cannot be used withhumanorshort.json-diagnostic-rendered-ansi: Ensure therenderedfield of JSON messages contains embedded ANSI color codes for respectingrustcโs default color scheme. Cannot be used withhumanorshort.json-render-diagnostics: Instruct Cargo to not includerustcdiagnostics in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming fromrustc. Cargoโs own JSON diagnostics and others coming fromrustcare still emitted. Cannot be used withhumanorshort.
๐ Common Options ๐
+toolchainโ If Cargo has been installed with rustup, and the first argument tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more information about how toolchain overrides work.--config KEY=VALUE or PATHโ Overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more information.-C PATHโ Changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. This option must appear before the command name, for examplecargo -C path/to/my-project build.
This option is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>).
so close to being usable on stable ๐ญ nightly girlies only fr fr
-h,--helpโ Prints help information.-Z flagโ Unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details.
๐ฑ ENVIRONMENT ๐ฑ
See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads.
๐ช EXIT STATUS ๐ช
0: Cargo succeeded. slay. ๐101: Cargo failed to complete. ๐
โจ EXAMPLES โจ
- Install or upgrade a package from crates.io:
cargo install ripgrep
- Install or reinstall the package in the current directory:
cargo install --path .
- View the list of installed packages:
cargo install --list
๐ SEE ALSO ๐
cargo(1), cargo-uninstall(1), cargo-search(1), cargo-publish(1)
okay bestie that's the whole page, you ate that ๐ this was CARGO-INSTALL(1) from the Cargo source (version and date on the real footer, mwah) โ go install something iconic, you got this ๐๐ฆ
๐ฆ where this page comes from
- centos-stream 10: cargo 1.99.1-1.el10 ยท (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- centos-stream 9: cargo 1.99.1-1.el9 ยท (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 43: cargo 1.99.0-1.fc43
- fedora 43: cargo 1.99.1-2.fc43 ยท (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 44: cargo 1.99.0-1.fc44
- fedora 44: cargo 1.99.1-2.fc44 ยท (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms