CARGO-UPDATE(1)

πŸ“¦ version 1.97.1, in ubuntu stonking

✨ CARGO-UPDATE(1) ✨

okay so welcome to the cargo-update page, bestie πŸ’– this is straight out of the General Commands Manual and it's literally the glow-up command for your dependency list. no cap.


πŸŽ€ NAME πŸŽ€

cargo-update β€” updates dependencies exactly as they're recorded in the local lock file πŸ¦‹

🌸 SYNOPSIS 🌸

cargo update [options] spec

πŸ’… DESCRIPTION πŸ’…

so here's the vibe: this command updates the dependencies inside your Cargo.lock file up to the latest version. that's the whole main character moment. 🌈

and if Cargo.lock doesn't even exist yet? not a problem β€” it'll be created for you, loaded up with the latest available versions. iconic behavior honestly πŸ‘‘

✨ OPTIONS ✨

πŸ› οΈ Update Options

  • spec… β€” only update the packages you name here, and yes you can drop this flag multiple times for multiple packages. the SPEC format lives over in cargo-pkgid(1), go peek 🫢

if you do pass packages with spec, you get a conservative update of the lockfile. translation: only the dependency you named in SPEC gets updated. its transitive dependencies will only move if SPEC literally cannot be updated without updating them. everything else stays locked at the versions currently recorded. no sneaky updates, we're being respectful πŸŽ€

if spec is not specified at all, then all dependencies get updated. full send πŸ’…

  • --recursive β€” when you use it with spec, the dependencies of spec are forced to update too. cannot be used with --precise. pick a lane bestie 😭
  • --precise precise β€” when you use it with spec, this lets you name a specific version number to pin 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 ✨
ngl, while it's not recommended, you can specify a yanked version of a package. when you can avoid it though, try other non-yanked SemVer-compatible versions, or go ask the package maintainers for help. yanked is yanked for a reason 🚩

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). okayyy πŸŒ™

  • --breaking directory β€” updates spec to the latest SemVer-breaking version. πŸ”₯

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 information. so like, don't try this on stable and then act surprised πŸ’€
  • -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 lowkey a lifesaver for updating Cargo.lock after you've changed version numbers in Cargo.toml. 🧚
  • --dry-run β€” shows you what would be updated, but doesn't actually write the lockfile. window shopping, no checkout πŸ›οΈ

πŸ‘€ Display Options

  • -v, --verbose β€” use verbose output. and yes, you can specify it twice for "very verbose" output, which includes extra stuff like dependency warnings and build script output. double the tea β˜•β˜• 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. silence is golden, periodt 🀫 may also be specified with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>.
  • --color when β€” controls when colored output is used. 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>.

πŸ“œ Manifest Options

  • --manifest-path path β€” path to the Cargo.toml file. by default, Cargo searches for Cargo.toml in the current directory or any parent directory. it will find it, it always finds it πŸ”
  • --ignore-rust-version β€” ignore the rust-version specification in packages. we're ignoring that, bestie πŸ™ˆ
  • --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 comes up:
    • 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 much a "trust the process" flag 🫢

  • --offline β€” prevents Cargo from accessing the network for any reason. without this flag, Cargo stops with an error if it needs the network and the network isn't available. with this flag, Cargo will attempt to proceed without the network if it can. airplane mode ✈️
beware bestie, this may result in a 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. plan ahead πŸ’…

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, we love a combo deal 🎁

🌟 Common Options

  • +toolchain β€” if Cargo has been installed with rustup, and the first argument to cargo begins with +, it'll be interpreted as a rustup toolchain name (like +stable or +nightly). see the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more on how toolchain overrides work. ✨
  • --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 information. 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, babes 😌
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. when in doubt, ask for help, that's self care πŸ’–
  • -Z flag β€” unstable (nightly-only) flags to Cargo. run cargo -Z help for details. the forbidden knowledge section πŸ•―οΈ

🌍 ENVIRONMENT 🌍

see the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads. it reads them, it's nosy, we respect it πŸ¦‹

🚦 EXIT STATUS 🚦

  • 0: Cargo succeeded. slay πŸŽ‰
  • 101: Cargo failed to complete. 😭 it's giving "we don't talk about it"

πŸ“ 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 πŸ’œ this one lives as CARGO-UPDATE(1) under the General Commands Manual β€” go update something and feel the main character energy, fr fr πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from