CARGO-UPDATE(1)

๐Ÿ‘‘ CARGO-UPDATE(1) ๐Ÿ‘‘

okay bestie, welcome to the cargo-update page โ€” it's a general commands manual page, and it's literally the glow-up button for your lockfile ๐Ÿ’…


โœจ NAME โœจ

cargo-update โ€” update dependencies as recorded in the local lock file ๐Ÿฆ‹


โœจ SYNOPSIS โœจ

cargo update [options] spec

โœจ DESCRIPTION โœจ

So this command updates the dependencies in the Cargo.lock file to the latest version. that's it, that's the whole vibe. ๐Ÿ”ฅ

And if the Cargo.lock file doesn't even exist yet? no worries, it gets created with the latest available versions. it's giving "manifesting your lockfile into existence" โœจ


โœจ OPTIONS โœจ

๐Ÿ’– Update Options

  • specโ€ฆ โ€” updates only the packages you name. you can drop this flag multiple times if you're feeling extra. the SPEC format lives over in cargo-pkgid(1), go peek at that for the deets.

Here's the tea tho: if you specify packages with spec, then a conservative update of the lockfile happens. translation? only the dependency named by SPEC gets updated. its transitive dependencies will only move if SPEC literally cannot be updated without moving them. everything else stays locked at the versions currently recorded. no chaotic cascade, we're being mindful ๐Ÿง˜

If spec is not specified, then ALL dependencies are updated. all of them. the whole squad. ๐ŸŒˆ

  • --recursive โ€” when you use this with spec, the dependencies of spec are forced to update too. but bestie, it cannot be used with --precise. they do not sit together, periodt. ๐Ÿ’€
  • --precise precise โ€” when used with spec, this lets you pin the package to a specific version number. and if the package comes from a git repository, precise can be a git revision โ€” like a SHA hash or a tag. yes, really. ๐Ÿ‘‘

Now, while it is not recommended, you can specify a yanked version of a package. if you can avoid it though, try other non-yanked SemVer-compatible versions, or go ask the package maintainers for help. ๐Ÿซถ

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

  • --breaking โ€” updates spec to the highest SemVer-breaking version. yes, we're breaking things on purpose. version requirements will be modified to allow this update. ๐Ÿ˜ญ

This only applies to dependencies when:

  • The package is a dependency of a workspace member
  • The dependency is not renamed
  • A SemVer-incompatible version is available
  • The "SemVer operator" is used (^, which is the default)
๐Ÿšจ heads up: this option is unstable and available only on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html), and it requires the -Z unstable-options flag to enable. See https://github.com/rust-lang/cargo/issues/12425 for more info.
  • -w, --workspace โ€” attempts to update only the packages defined in the workspace. other packages get updated only if they don't already exist in the lockfile. this one is so useful for updating Cargo.lock after you've changed version numbers in Cargo.toml. chef's kiss ๐Ÿ‘ฉโ€๐Ÿณ๐Ÿ’‹
  • --dry-run โ€” shows you what would be updated, but doesn't actually write the lockfile. window shopping only, no purchasing. ๐Ÿ›๏ธ

๐Ÿ’œ Display Options

  • -v, --verbose โ€” 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). she's chatty and we love her ๐Ÿ—ฃ๏ธ
  • -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). silent mode, main character mystery energy ๐Ÿคซ
  • --color when โ€” controls 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). aesthetic is configurable, as it 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 goes looking for its home ๐Ÿ 
  • --ignore-rust-version โ€” ignore the rust-version specification in packages. ignoring the rules, iconic behaviour ๐Ÿ™ˆ
  • --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.

You'd use this in environments where deterministic builds are desired, such as CI pipelines. no surprises allowed, we're locked in fr fr ๐Ÿ”’

  • --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 builds โœˆ๏ธ
โš ๏ธ beware: 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. two-for-one deal, we love a bundle ๐ŸŽ€

๐Ÿ’› 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 (https://rust-lang.github.io/rustup/overrides.html) for more info about how toolchain overrides work. pick your fighter โš”๏ธ
  • --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 (https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides) for more info. stack 'em up ๐Ÿฅž
  • -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. order matters bestie, don't fight it ๐Ÿ’…
๐ŸŒ™ 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).
  • -h, --help โ€” prints help information. when in doubt, ask for help, that's growth ๐ŸŒฑ
  • -Z flag โ€” unstable (nightly-only) flags to Cargo. run cargo -Z help for details. the forbidden zone, enter with caution ๐Ÿ”ฎ

โœจ 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. ๐ŸŽ‰
  • 101: Cargo failed to complete. ๐Ÿ˜ญ

โœจ 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) ๐Ÿซถ


aaaand that's the whole page bestie!! this was CARGO-UPDATE(1) from the General Commands Manual โ€” the footer just says CARGO-UPDATE(1) again, no extra version or date tea in there. go update those deps, slay, and remember: conservative updates only when you say so ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from