LinuxCommandLibrary

cargo-update

Update installed Rust binary crates

TLDR

Update dependencies in Cargo.lock to the latest possible version

$ cargo update
copy

Display what would be updated, but don't actually write the lockfile
$ cargo update [[-n|--dry-run]]
copy

Update only the specified dependencies
$ cargo update --package [dependency1] --package [dependency2] --package [dependency3]
copy

Set a specific dependency to a specific version
$ cargo update --package [dependency] --precise [1.2.3]
copy

SYNOPSIS

cargo install-update [OPTIONS] [CRATE...]
cargo install-update --all [OPTIONS]
cargo install-update --list

PARAMETERS

CRATE...
    Specifies one or more names of cargo crates (tools) to update. If no crates are specified and --all is not used, it typically does nothing or lists usage.

-a, --all
    Updates all cargo crates that were previously installed using cargo install. This is the most common use case for bulk updates.

-l, --list
    Lists all cargo crates that are currently installed and can be managed by cargo install-update, along with their versions.

-f, --force
    Forces recompilation of crates even if they appear to be up to date, useful for resolving potential issues or rebuilding with different flags.

--dry-run
    Performs a dry run, showing what actions would be taken (e.g., which crates would be updated) without actually modifying anything on the system.

-v, --verbose
    Uses verbose output, providing more detailed information about the update process, including compilation steps.

--git GIT
    Updates a crate from a specified Git repository URL instead of crates.io. Useful for development versions.

--path PATH
    Updates a crate from a local filesystem path. This is useful when developing the tool itself.

--target TARGET
    Compiles the crate for a specific target triple (e.g., x86_64-unknown-linux-gnu).

--features FEATURES
    A space-separated list of features to compile with. Overrides default features.

--no-default-features
    Do not compile with default features. Often used in conjunction with --features.

--all-features
    Compile with all available features.

--profile PROFILE
    Specifies the Cargo build profile to use (e.g., release for optimized, production-ready binaries, or dev for faster debug builds).

--debug
    Builds the crate with debug information. Equivalent to --profile dev but often explicitly stated for clarity.

--jobs JOBS
    Number of parallel jobs to run during compilation. Useful for controlling resource usage on multi-core systems.

--locked
    Requires Cargo.lock to be up to date. If Cargo.lock is missing or outdated, an error is produced.

--offline
    Compiles without network access, using only cached dependencies. This requires all necessary dependencies to be present locally.

--bin-path PATH
    Specifies an alternative path where the updated binaries should be installed, overriding the default $CARGO_HOME/bin.

--root ROOT
    Installs the updated crate into a specific root directory structure, similar to how cargo install --root works.

--allow-prerelease
    Allows updating to prerelease versions (e.g., 0.1.0-alpha.1) of crates, which are typically ignored by default.

-h, --help
    Displays a help message with command usage and options, then exits.

DESCRIPTION

The cargo-update command, typically invoked as cargo install-update, is a vital utility for Rust developers to manage and keep their global cargo subcommands up-to-date.

While cargo update (without the 'install-' prefix) is a built-in cargo command used for refreshing project dependencies defined in Cargo.toml, cargo install-update focuses specifically on binaries previously installed using cargo install.

It addresses a common need in the Rust ecosystem by providing a convenient way to re-download and re-compile the latest versions of your globally installed development tools (e.g., cargo-audit, cargo-watch, cargo-expand). This process involves querying crates.io (the Rust package registry) for newer versions and then recompiling the tool, ensuring you always have the most recent features and bug fixes.

It's an essential tool for maintaining a healthy and current Rust development environment.

CAVEATS

cargo-update is a third-party tool and not part of the core cargo distribution. It must be installed separately via cargo install cargo-update before it can be used.

Updates involve recompiling Rust code, which can consume significant CPU and time, especially for many tools or on less powerful systems. The compilation process requires the Rust toolchain (compiler, linker) to be properly set up.

It relies on the availability of network access to crates.io for fetching new versions and their dependencies, unless the --offline flag is used and all dependencies are cached.

<I>INSTALLATION</I>

To use cargo install-update, you must first install it using cargo itself. This is typically a one-time setup:
cargo install cargo-update

After successful installation, the command is usually available as cargo install-update, or simply cargo update if your shell's path resolves it differently (though the former is recommended to avoid confusion).

<I>DISTINCTION FROM CARGO UPDATE</I>

It is important to differentiate cargo install-update from the built-in cargo update command. While both deal with 'updating', cargo update (without 'install-') is used within a Rust project directory to update that project's dependencies as specified in its Cargo.lock file. cargo install-update, conversely, manages standalone binaries installed globally on your system via cargo install, independently of any specific project's dependencies.

HISTORY

The need for a dedicated command to update globally installed cargo subcommands became apparent as the Rust ecosystem matured and more tools were distributed via cargo install. Prior to cargo-update's widespread adoption, developers often had to manually cargo uninstall and then cargo install each tool to update them, a cumbersome process.

cargo-update (originally cargo-install-update) was created by Alex Crichton, a prominent member of the Rust team, to streamline this process. It quickly became an essential tool for managing a growing collection of Rust command-line utilities, filling a crucial gap in the cargo toolchain. Its development and maintenance are now often handled by the crate-ci group, ensuring its continued relevance and functionality within the Rust development workflow.

SEE ALSO

cargo(1), cargo-install(1), rustup(1), rustc(1)

Copied to clipboard