CARGO-UPDATE(1)

๐Ÿ“ฆ version 1.80.1, in ubuntu jammy, ubuntu noble

โœจ cargo-update โ€” the glow-up your Cargo.lock deserves โœจ

okay bestie, welcome to the cargo-update(1) page from the General Commands Manual ๐Ÿ’– this is the little command that refreshes your dependencies, and honestly? it's giving main character energy. let's get into it ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

cargo-update โ€” Update dependencies as recorded in the local lock file

like, it updates your deps. that's the vibe. periodt. ๐Ÿ’…


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

cargo update [options] spec

short, sweet, iconic. no cap.


๐ŸŽ€ DESCRIPTION ๐ŸŽ€

so basically, this command updates the dependencies in your Cargo.lock file to the latest version. that's the whole mission, that's the whole plot ๐Ÿ’–

and if the Cargo.lock file doesn't exist yet? no worries bestie โ€” Cargo will just create it for you, already filled with the latest available versions. it's literally born ready. โœจ


๐Ÿ‘‘ OPTIONS ๐Ÿ‘‘

๐Ÿ’œ Update Options ๐Ÿ’œ

  • specโ€ฆ โ€” Update only the packages you name here. This flag can be specified multiple times (you can stack it, you're allowed ๐Ÿ’…). Peep cargo-pkgid(1) for the SPEC format, iykyk.

If you do pass packages with spec, then a conservative update of the lockfile happens. What does that mean? Only the dependency named by SPEC gets updated. Its transitive dependencies only get updated if SPEC literally cannot be updated without updating them. Everything else stays locked at the versions currently recorded. so basically: minimal chaos, maximum control ๐ŸŽ€

And if you don't specify spec? Then all dependencies get updated. go big or go home. ๐Ÿ”ฅ

  • --recursive โ€” When used with spec, the dependencies of spec are forced to update as well. Cannot be used with --precise. pick a lane bestie ๐Ÿ˜ญ
  • --precise precise โ€” When used with spec, this lets you specify an exact version number to set the package to. And if the package comes from a git repository, this can be a git revision (like a SHA hash or a tag). very specific, very demure โœจ
โš ๏ธ While not recommended, you can specify a yanked version of a package. When possible, try other non-yanked SemVer-compatible versions, or go ask the package maintainers for help. yanked versions are lowkey a red flag, bestie ๐Ÿ’€

A compatible pre-release version can also be specified even when the version requirement in Cargo.toml doesn't contain any pre-release identifier โ€” but heads up, that's nightly only. ๐ŸŒ™

  • -w, --workspace โ€” Attempt to update only packages defined in the workspace. Other packages are updated only if they don't already exist in the lockfile. This one is super useful for updating Cargo.lock after you've changed version numbers in Cargo.toml. chef's kiss ๐Ÿ‘ฉโ€๐Ÿณ๐Ÿ’‹
  • --dry-run โ€” Displays what would be updated, but doesn't actually write the lockfile. it's the window-shopping of dependency management ๐Ÿ›๏ธ

๐ŸŒˆ 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 the term.verbose config value: https://doc.rust-lang.org/cargo/reference/config.html. the more -v you add, the more it yaps ๐Ÿ—ฃ๏ธ
  • -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. shhh, it's napping ๐Ÿ˜ด
  • --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. aesthetics are configurable, as they should be ๐Ÿ’…

๐Ÿงš Manifest Options ๐Ÿงš

  • --manifest-path path โ€” Path to the Cargo.toml file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory. it's a little detective ๐Ÿ”
  • --ignore-rust-version โ€” Ignore rust-version specification in packages. who even needs it, right? (jk, it's there for a reason, but this flag says "not today") ๐Ÿ™ˆ
  • --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. locked in, literally ๐Ÿ”’

  • --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. airplane mode but for crates โœˆ๏ธ
โš ๏ธ 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. ๐Ÿ‘€

May also be specified with the net.offline config value: https://doc.rust-lang.org/cargo/reference/config.html.

  • --frozen โ€” Equivalent to specifying both --locked and --offline. it's the combo meal ๐Ÿ”๐ŸŸ

โญ Common Options โญ

  • +toolchain โ€” If Cargo has been installed with rustup, and the first argument to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +nightly). See the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more information about how toolchain overrides work. yes queen, pick your toolchain ๐Ÿ’…
  • --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 at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information. stack those configs, girl ๐ŸŽ€
  • -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 example 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 at https://github.com/rust-lang/cargo/issues/10098). nightly girlies only ๐Ÿ’œ
  • -h, --help โ€” Prints help information. when in doubt, ask for help, bestie ๐Ÿซถ
  • -Z flag โ€” Unstable (nightly-only) flags to Cargo. Run cargo -Z help for details. the secret menu ๐Ÿ”ฎ

๐ŸŒธ ENVIRONMENT ๐ŸŒธ

See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. it reads env vars, it has feelings, it's a whole person ๐Ÿ’–


๐Ÿฆ‹ EXIT STATUS ๐Ÿฆ‹

  • 0: Cargo succeeded. ๐ŸŽ‰
  • 101: Cargo failed to complete. ๐Ÿ˜ญ

those are the only two moods fr fr.


โœจ EXAMPLES โœจ

  1. Update all dependencies in the lockfile:
cargo update
  1. Update only specific dependencies:
cargo update foo bar
  1. Set a specific dependency to a specific version:
cargo update foo --precise 1.2.3

๐ŸŽ€ SEE ALSO ๐ŸŽ€

cargo(1), cargo-generate-lockfile(1)


and that's the whole page bestie, you ate that ๐Ÿ’… thanks for reading the cargo-update(1) page from the General Commands Manual โ€” now go update those deps and slay ๐Ÿ”ฅ๐Ÿฆ‹๐Ÿ’–

๐Ÿ“ฆ where this page comes from