CARGO-INSTALL(1)
cargo-install π
okay bestie, welcome to cargo-install β it's a page in the General Commands Manual and it's literally about building and installing a Rust binary. let's gooo β¨
β¨ NAME β¨
cargo-install β build and install a Rust binary π¦
π SYNOPSIS π
cargo install [options] crate[@version]β¦
cargo install [options] --path path
cargo install [options] --git url [crateβ¦]
cargo install [options] --list
π DESCRIPTION π
so basically this command is the one that manages Cargo's local lil collection of installed binary crates. only packages that have executable [[bin]] or [[example]] targets can even be installed, bestie β no binaries, no entry. and every single executable gets dropped into the installation root's bin folder. by default it installs only binaries, not examples. periodt.
the installation root gets figured out in this exact order of precedence, top one 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
now, there are multiple sources a crate can come from, and this is the part where it gets spicy πΆοΈ. the default source location is crates.io, but the --git, --path, and --registry flags can switch that source up. and if the source has more than one package in it (think crates.io, or a git repo with a whole pile of crates in it), then the crate argument becomes required so Cargo knows which crate you actually mean. no crate name = Cargo's just standing there like π§
crates from crates.io can optionally say which version they want via the --version flags, and same energy for packages from git repos β you can optionally name the branch, tag, or revision that should be installed. if a crate has multiple binaries, the --bin argument lets you selectively install just one of them, and if you'd rather install examples, the --example argument is right there for you too. obsessed. π«Ά
if the package is already installed, Cargo will reinstall it whenever the installed version doesn't look up-to-date. and if any of these values change, Cargo reinstalls the package, no cap:
- 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 can be used to force Cargo to always reinstall the package, every time, no questions.
if the source is crates.io or --git, then by default the crate gets built in a temporary target directory. to avoid that, you can specify the target directory by setting the CARGO_TARGET_DIR environment variable to a relative path. this is especially useful for caching build artifacts on continuous integration systems. iykyk π
πΈ Dealing with the Lockfile πΈ
by default, the Cargo.lock file that ships with the package gets ignored. what that means: Cargo will recompute which versions of dependencies to use, possibly pulling in newer versions that got released after the package was published. sneaky.
the --locked flag forces Cargo to use the packaged Cargo.lock file if it's available. this is useful for ensuring reproducible builds β using the exact same set of dependencies that existed when the package was published. it's also 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? you will not receive any fixes or updates to any dependency. trade-offs, bestie.
note: Cargo didn't start publishingCargo.lockfiles until version1.37, which means packages published with prior versions won't have aCargo.lockfile available at all. sad but true π₯²
π¦ 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) gets ignored entirely. instead, configuration discovery begins at $CARGO_HOME/config.toml.
but wait β if the package is installed with --path $PATH, then the local configuration will be used, and discovery begins at $PATH/.cargo/config.toml. slay.
β¨ OPTIONS β¨
π Install Options π
--versversion,--versionversion β specify a version to install. this can be a version requirement (https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html), like~1.2, which makes Cargo pick the newest version matching that requirement. if the version has no requirement operator (like^or~), then it must be in the formMAJOR.MINOR.PATCH, and it'll install exactly that version β it is not treated as a caret requirement like Cargo dependencies are. important distinction, don't sleep on it.--giturl β the git URL to install the specified crate from.--branchbranch β which branch to use when installing from git.--tagtag β which tag to use when installing from git.--revsha β the specific commit to use when installing from git.--pathpath β filesystem path to the local crate you want to install from.--listβ list all installed packages and their versions. cute lil inventory π§Ύ-n,--dry-runβ (unstable) perform all the checks without actually installing. all vibes, no commitment.-f,--forceβ force overwriting existing crates or binaries. use this if a package has installed a binary with the same name as another package. also useful if something on the system changed and you want to rebuild with it β like a newer version ofrustc, for example.--no-trackβ by default, Cargo keeps track of the installed packages using 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. it also disables Cargo's ability to protect against multiple concurrent invocations of Cargo installing at the same time. β οΈ--binnameβ¦ β install only the specified binary.--binsβ install all binaries. this is the default behavior.--examplenameβ¦ β install only the specified example.--examplesβ install all examples.--rootdir β directory to install packages into.--registryregistry β name of the registry to use. registry names are defined in Cargo config files (https://doc.rust-lang.org/cargo/reference/config.html). if you don't specify one, the default registry is used β which is defined by theregistry.defaultconfig key, and that defaults tocrates-io.--indexindex β the URL of the registry index to use.
π Feature Selection π
the feature flags let you control which features get 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. π
-Ffeatures,--featuresfeatures β 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, and that enables all the specified features. the more the merrier β¨--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 π¦
--targettriple β install for the given architecture. the default is the host architecture. the general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. runrustc --print target-listfor a list of supported targets.
this may also be specified with the build.target config value (https://doc.rust-lang.org/cargo/reference/config.html).
heads up: specifying this flag makes Cargo run in a different mode, where the target artifacts are placed in a separate directory. see the build cache documentation (https://doc.rust-lang.org/cargo/reference/build-cache.html) for more details.
--target-dirdirectory β 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 the target directory in the workspace of the local crate, unless --target-dir is specified.
--debugβ build with thedevprofile instead of thereleaseprofile. see also the--profileoption for choosing a specific profile by name.--profilename β install with the given profile. see the reference (https://doc.rust-lang.org/cargo/reference/profiles.html) for more details on profiles.--timings=fmtsβ output information on how long each compilation takes, and track concurrency information over time. accepts an optional comma-separated list of output formats;--timingswithout an argument will default to--timings=html. specifying an output format (rather than the default) is unstable and requires-Zunstable-options. valid output formats:html(unstable, requires-Zunstable-options): write a human-readable filecargo-timing.htmlto thetarget/cargo-timingsdirectory with a report of the compilation. also write a report to the same directory with a timestamp in the filename, if you want to look at older runs. HTML output is suitable for human consumption only, and does not provide machine-readable timing data.json(unstable, requires-Zunstable-options): emit machine-readable JSON information about timing information.
πΈ 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 these scenarios arises:- the lock file is missing
- Cargo attempted to change the lock file due to a different dependency resolution
this 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 isn't available. with this flag, Cargo will attempt to proceed without the network if possible.
beware bestie: this may result in different dependency resolution than online mode. 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. see the cargo-fetch(1) command to download dependencies before going offline. π«Ά
β¦and yeah, that --offline vibe? You can also set it with the net.offline config value β https://doc.rust-lang.org/cargo/reference/config.html.
--frozenβ Two-for-one deal, bestie. Same as passing both--lockedand--offlineat once. Periodt.
π§© Miscellaneous Options π§©
-j N,--jobs Nβ How many jobs can run in parallel, bestie? You can also set it with thebuild.jobsconfig value βhttps://doc.rust-lang.org/cargo/reference/config.html. Defaults to the number of logical CPUs. If it's negative, it sets the max number of parallel jobs to the number of logical CPUs plus the value you gave. If a string default is provided, it sets the value back to defaults. Should not be 0. Like, do not.--keep-goingβ Build as many crates in the dependency graph as possible, instead of aborting the whole build the moment one of them fails to build. π
So like, imagine your current package depends on two deps, one that fails to build and one that works. cargo install -j1 may or may not build the one that succeeds (it depends on which of the two builds Cargo picked to run first π), whereas cargo install -j1 --keep-going would definitely run both builds, even if the one it runs first fails. Slay, resilience.
π¨ Display Options π¨
-v,--verboseβ Use verbose output. You can specify it twice for "very verbose" output, which includes extra stuff like 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.
--message-format fmtβ The output format for diagnostic messages. Can be specified multiple times, and it's made 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 tostdout. See the reference for more details βhttps://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages. 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, so it respectsrustc's default color scheme. Cannot be used withhumanorshort.json-render-diagnostics: Instruct Cargo to not includerustcdiagnostics in the JSON messages it prints, and instead have Cargo itself render the JSON diagnostics coming fromrustc. Cargo's own JSON diagnostics and the others coming fromrustcare still emitted. Cannot be used withhumanorshort.
π Common Options π
+toolchainβ If Cargo was installed with rustup, and the first argument tocargostarts with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly). See the rustup documentation for more on how toolchain overrides work βhttps://rust-lang.github.io/rustup/overrides.html.--config KEY=VALUE or PATHβ Overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=VALUE, or given as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section for more info βhttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides.-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), and also the directories it searches for discovering.cargo/config.toml, for example. This option must appear before the command name, likecargo -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 it requires the-Z unstable-optionsflag to enable (see #10098 βhttps://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ Prints help information. π«Ά-Z flagβ Unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details.
π ENVIRONMENT π
See the reference for details on environment variables that Cargo reads β https://doc.rust-lang.org/cargo/reference/environment-variables.html. iykyk, the env vars are always lurking.
πͺ EXIT STATUS πͺ
0: Cargo succeeded. β¨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)
and that's the whole page, bestie π This was CARGO-INSTALL(1) β that's the source/version-and-date footer at the bottom of the man page, and I'm mentioning it here instead of just copying it, because we're cute like that. Go install something iconic. π
π
π¦ where this page comes from
- ubuntu jammy: cargo-1.84 1.84.1+dfsg0ubuntu1~bpo10-0ubuntu4.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.84 1.84.1+dfsg0ubuntu1~bpo2-0ubuntu2.24.04.1 Β· Apache-2.0 WITH LLVM exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms