CARGO-INSTALL(1)

πŸ“¦ version 1.92.0, in ubuntu resolute

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:

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 publishing Cargo.lock files until version 1.37, which means packages published with prior versions won't have a Cargo.lock file 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 form MAJOR.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 of rustc.
  • --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 --force is 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 the registry.default config key β€” and that defaults to crates-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 with package-name/feature-name syntax. 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, 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 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 the CARGO_TARGET_DIR environment variable, or the build.target-dir config 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 the dev profile instead of the release profile. see also the --profile option 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; --timings without 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 file cargo-timing.html to the target/cargo-timings directory 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 β€” ignore rust-version specification in packages. we're pretending we didn't see it.
  • --locked β€” asserts that the exact same dependencies and versions are used as when the existing Cargo.lock file 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 --locked and --offline. that's it, that's the option.

πŸŽ€ Miscellaneous Options πŸŽ€

  • -j N, --jobs N β€” how many parallel jobs do we run? πŸƒβ€β™€οΈπŸƒβ€β™€οΈ May also be specified with the build.jobs config 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 string default is provided, it sets the value back to defaults. And ngl β€” it should not be 0.
  • --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 the term.verbose config value: https://doc.rust-lang.org/cargo/reference/config.html.
  • -q, --quiet β€” do not print cargo log messages 🀫 May also be specified with the term.quiet config value: https://doc.rust-lang.org/cargo/reference/config.html.
  • --color when β€” 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-format fmt β€” 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 with short and json.
    • short: emit shorter, human-readable text messages. Conflicts with human and json.
    • 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 with human and short.
    • json-diagnostic-short: ensure the rendered field of JSON messages contains the "short" rendering from rustc. Cannot be used with human or short.
    • json-diagnostic-rendered-ansi: ensure the rendered field of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. Cannot be used with human or short.
    • 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 with human or short.

πŸ’œ Common Options πŸ’œ

  • + toolchain β€” if Cargo has been installed with rustup, and the first argument to cargo begins with +, it gets interpreted as a rustup toolchain name (like +stable or +nightly). See the rustup documentation for more info 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 of KEY=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.
  • -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, 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-options flag to enable (see #10098: https://github.com/rust-lang/cargo/issues/10098).
  • -h, --help β€” prints help information. the "bestie I'm lost" button 🫢
  • -Z flag β€” unstable (nightly-only) flags to Cargo. Run cargo -Z help for 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 πŸ¦‹

  1. Install or upgrade a package from crates.io:
cargo install ripgrep
  1. Install or reinstall the package in the current directory:
cargo install --path .
  1. 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