CARGO-INSTALL(1)
bestie, this is CARGO-INSTALL(1) straight out of the General Commands Manual β aka the whole entire vibe of cargo install β and we are getting through it together π no skimming, no skipping, we're reading the whole thing.
πΈ NAME πΈ
cargo-install β literally just build a Rust binary and install it. that's the job. that's the whole job β¨
π¦ SYNOPSIS π¦
cargo install [options] crate[@version]β¦
cargo install [options] --path path
cargo install [options] --git url [crateβ¦]
cargo install [options] --list
π DESCRIPTION π
okay so. this command is the one running the show for Cargo's local set of installed binary crates β like, your personal lil collection of installed binaries π
only packages that have executable [[bin]] or [[example]] targets can be installed, periodt. and every single executable lands in the installation root's bin folder. by default it's binaries only, not examples β examples don't get installed unless you say so.
now. where does that installation root even live? it's decided in order of precedence, bestie, so read it top to bottom:
--rootoptionCARGO_INSTALL_ROOTenvironment variableinstall.rootCargo config value (https://doc.rust-lang.org/cargo/reference/config.html)CARGO_HOMEenvironment variable$HOME/.cargo
there are multiple sources you can install a crate from, which is lowkey so many options of you. the default source location is crates.io, but the --git, --path, and --registry flags can all change that source up. and if the source contains more than one package (like crates.io, or a git repo with multiple crates in it), then the crate argument is required β you gotta tell Cargo which crate you mean, no guessing π
crates from crates.io can optionally specify the version they wish to install via the --version flags, and similarly packages from git repos 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 too π
if the package is already installed, Cargo will reinstall it if the installed version doesn't appear to be up-to-date. if any of these values change, Cargo reinstalls the package:
- 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 single time, no questions asked π
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 β very much the move if you're tired of rebuilding the same thing forever β¨
π Dealing with the Lockfile π
by default, the Cargo.lock file that's included 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. very "we'll figure it out" of it.
the --locked flag can force 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 were available 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 of --locked: you won't receive any fixes or updates to any dependency. tradeoffs, bestie.
note that Cargo didn't start publishingCargo.lockfiles until version 1.37, which means packages published with prior versions won't have aCargo.lockfile available at all. not a vibe, just a fact.
π Configuration Discovery π
this command operates at the 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.
if the package is installed with --path $PATH, then the local configuration is used, and discovery begins at $PATH/.cargo/config.toml.
β¨ OPTIONS β¨
π Install Options π
--vers version,--version versionβ specify a version to install. this can 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 doesn't have a 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. read that twice bestie, it matters.--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 the local crate to install from.--listβ list all installed packages and their versions. yes, just the list, the receipts π§Ύ-n,--dry-runβ (unstable) perform all the checks without actually installing anything. window shopping.-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. it's also useful if something changed on the system and you want to rebuild with it, like a newer version ofrustc.--no-trackβ by default, Cargo keeps track of 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--forceis also used. it also disables Cargo's ability to protect against multiple concurrent invocations of Cargo installing at the same time β so heads up on that one π«Ά--bin nameβ¦β install only the specified binary.--binsβ install all binaries. this is the default behavior, so like, it's already doing this.--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 β and that defaults tocrates-io.--index indexβ 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. cute and predictable π
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 the specified features.--all-featuresβ activate all available features of all selected packages. go big.--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, anxtaskin 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 get 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'll 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.--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=fmtsβ output information about 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. we're pretending we didn't see it.--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.
it may be used in environments where deterministic builds are desired, such as in CI pipelines. very serious, very structured, we respect it π
more of this page is coming bestie, don't go anywhere π
--offlineβ okay so this one is giving β "no internet, not today." It stops Cargo from touching the network for any reason. Without this flag, if Cargo needs the network and the network is justβ¦ not available, it stops with an error. With the flag, Cargo will try to proceed without the network if it possibly can.
π¨ but bestie, beware: this may result in a different dependency resolution than online mode. Cargo restricts itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. Want your deps all cozy at home before you go dark? See the cargo-fetch(1) command to download dependencies before going offline.
May also be specified with the net.offline config value: https://doc.rust-lang.org/cargo/reference/config.html.
--frozenβ the combo meal π it's equivalent to specifying both--lockedand--offline. that's it, that's the option.
π Miscellaneous Options π
-jN,--jobsN β how many parallel jobs do we 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 the value you provided. If a stringdefaultis provided, it sets the value back to defaults. And ngl β it should not be0.--keep-goingβ build as many crates in the dependency graph as possible, instead of aborting the build on the first one that fails to build. main character energy: keep the show going π
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.
π Display Options π
-v,--verboseβ use verbose output. You can specify it 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.--colorwhen β control when colored output is used. The valid values are: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-formatfmt β the output format for diagnostic messages. Can be specified multiple times, and it's made of comma-separated values. The 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 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 from rustc. Cannot be used withhumanorshort.json-diagnostic-rendered-ansi: ensure therenderedfield of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. Cannot be used withhumanorshort.json-render-diagnostics: instruct Cargo to not include rustc diagnostics in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others coming from rustc are still emitted. Cannot be used withhumanorshort.
π Common Options π
+toolchain β if Cargo has been installed with rustup, and the first argument tocargobegins with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly). See the rustup documentation for more info on how toolchain overrides work:https://rust-lang.github.io/rustup/overrides.html.--configKEY=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 for more:https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides.-CPATH β 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, like:
cargo -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-optionsflag to enable (see #10098:https://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information. the "bestie I'm lost" button π«Ά-Zflag β 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.
β¨ 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 π
and that's the whole page, bestie π the little footer at the very bottom is just CARGO-INSTALL(1) β that's this page's name and section number, the source/version-and-date stamp of the cargo manual it lives in. nothing else hiding down there. go install something iconic, periodt β¨
π¦ where this page comes from
- ubuntu resolute: cargo-1.93 1.93.1+dfsg-0ubuntu6 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms