CARGO-INSTALL(1)
π CARGO-INSTALL(1) β NAME
okay bestie, welcome to the manual page for cargo-install (it lives in the General Commands Manual, and it is so the moment). here's the whole vibe in one line:
cargo-install β Build and install a Rust binary
that's it. that's the tweet. now let's get into it π«Ά
β¨ SYNOPSIS β¨
like, the shapes this command comes in:
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 literally the manager of Cargo's local little collection of installed binary crates. only packages that have executable [[bin]] or [[example]] targets can even be installed β everyone else, sorry, not your era. and all the executables get dropped into the bin folder of the installation root. by default only binaries get installed, not examples. (examples are a whole separate choice, we'll get there.)
π where does stuff even go (the installation root)
the installation root gets figured out in order of precedence, so the first one that applies 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
π where crates come from
there are multiple sources a crate can be installed from, bestie. the default location is crates.io, but the --git, --path, and --registry flags can switch that up entirely. if the source has more than one package in it (think crates.io, or a git repo holding multiple crates), then the crate argument is required so Cargo knows which crate you actually mean. no crate arg, no install. periodt.
crates from crates.io can optionally say which version they want via the --version flags, and same energy for packages from git repos β they can optionally specify 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 instead, the --example argument is right there waiting for you π
π when does it reinstall?
if the package is already installed, Cargo will reinstall it if the installed version does not appear to be up-to-date. and if any of these values change, Cargo will reinstall 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. no cap.
ποΈ temp target dirs
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 relative path. this is lowkey perfect for caching build artifacts on continuous integration systems, iykyk β¨
π Dealing with the Lockfile
by default, the Cargo.lock file that ships with the package is ignored. meaning: Cargo will recompute which versions of dependencies to use, possibly grabbing newer versions that got released after the package was published. (chaotic, but that's the default.)
the --locked flag can force Cargo to use the packaged Cargo.lock file if it is available. this is useful for:
- ensuring reproducible builds β using the exact same set of dependencies that were available when the package was published
- when a newer version of a dependency gets published that no longer builds on your system, or has other problems
the downside of --locked? you will not receive any fixes or updates to any dependency. it's giving "frozen in time" π§
β οΈ note that Cargo did not start publishingCargo.lockfiles until version 1.37, which means packages published with prior versions will not have aCargo.lockfile available. so like, if it's not there, it's not there.
π Configuration Discovery
this command operates on system or user level, not project level. so the local configuration discovery (https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure) is ignored.
instead, the configuration discovery begins at $CARGO_HOME/config.toml.
but β plot twist β if the package is installed with --path $PATH, then the local configuration will be used, beginning discovery at $PATH/.cargo/config.toml. bestie gets the local treatment only when they ask for it π
π 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, so Cargo picks the newest version matching that requirement. but if the version does not have a requirement operator (like^or~), then it has to be in the formMAJOR.MINOR.PATCH, and it will install exactly that version β it is not treated as a caret requirement like Cargo dependencies are. read that twice, it's the trap πͺ€--git urlβ the 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.--listβ list all installed packages and their versions.-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 changed on the system that you want to rebuild with β like a newer version ofrustc. slay.--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 the--forceflag is used. this also disables Cargo's ability to protect against multiple concurrent invocations of Cargo installing at the same time. (so like, don't run ten of them at once, bestie π)--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 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. go read it, it's giving essential.
-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. all of them. every last one.--no-default-featuresβ do not activate the default feature of the selected packages.
π¨ Compilation Options
--target tripleβ 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).
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 documentation (https://doc.rust-lang.org/cargo/guide/build-cache.html) for more details. it's giving "different directory, different era" π¦
--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 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.--ignore-rust-versionβ install the target even if the selected Rust compiler is older than the required Rust version as configured in the project'srust-versionfield. (living dangerously, I respect it π)--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
--frozen,--lockedβ either of these flags requires that theCargo.lockfile is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error. the--frozenflag also prevents Cargo from attempting to access the network to determine if it is out-of-date.
these may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build), or where you want to avoid network access entirely.
--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 that 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. (prep ahead of time, bestie, it's the move π«Ά)
okay that's the first half of the page β more is coming, don't go anywhere π
okay so that last one? you can also set it with the net.offline config value (https://doc.rust-lang.org/cargo/reference/config.html). bestie energy, config-file energy, same thing π
π Miscellaneous Options π
-jN,--jobsN β how many parallel jobs to run, like, at once. you can also set this 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 it. if you pass a string default, it sets the value back to defaults. and it should not be0, periodt.--keep-goingβ build as many crates in the dependency graph as possible instead of aborting the whole build on the first one that fails. main character resilience fr fr β¨
for example: if the current package depends on dependencies that fail and work β one of which fails to build βcargo install -j1may or may not build the one that succeeds (depends on which one of the two builds Cargo picked to run first), whereascargo install -j1 --keep-goingwould definitely run both builds, even if the one run first fails. that's the difference, no cap.
β¨ Display Options β¨
-v,--verboseβ use verbose output. say it twice for "very verbose" output, which includes extra stuff like dependency warnings and build script output. you can also set this with theterm.verboseconfig value (https://doc.rust-lang.org/cargo/reference/config.html). the way she yaps π¬-q,--quietβ do not print cargo log messages. you can also set this with theterm.quietconfig value (https://doc.rust-lang.org/cargo/reference/config.html). silence is golden, lowkey iconic π€«--colorwhen β controls when colored output is used. valid values:auto(default): automatically detect if color support is available on the terminal. she's intuitive πalways: always display colors. rainbow mode, we love her πnever: never display colors. minimalist era.
you can also set this 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. 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 withrustup, and the first argument tocargobegins with+, it'll be interpreted as arustuptoolchain name (like+stableor+nightly). see the rustup documentation (https://rust-lang.github.io/rustup/overrides.html) for more info on how toolchain overrides work. pick your fighter π«Ά--configKEY=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 (https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides) for more info.-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), and also 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.
heads up bestie: 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 #10098https://github.com/rust-lang/cargo/issues/10098). unstable girlie things π
-h,--helpβ prints help information. when you're lost, she's there π-Zflag β unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details. forbidden knowledge, iykyk π₯
πΈ 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. ate π101: Cargo failed to complete. it's giving tragedy π
β 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) from the Cargo manual β source and version stamped by the Cargo crew, dated whenever your copy shipped β so go forth and install things, you absolute icon π¦π
π¦ where this page comes from
- ubuntu jammy: cargo-1.76 1.76.0+dfsg0ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.76 1.76.0+dfsg0ubuntu1-0ubuntu0.24.04.2 Β· 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