Usually, I only care to know about the version number of a crate when I'm going to add the crate to my Cargo.toml. In those cases, I use two extra Cargo subcommands from the cargo-edit project:
cargo add — adds the current stable version of a crate to Cargo.toml. Options exist for allowing prerelease versions or marking it as a build / dev dependency.cargo upgrade — updates the version of a crate already in Cargo.toml. Similar to cargo update, but also changes Cargo.toml in addition to Cargo.lock.As of Rust 1.41.0, you can use the following command to update crates to their latest version:
cargo install <crate>
This came from pull request #6798 (Add install-upgrade) and was stabilized in #7560 (Stabilize install-upgrade).
Instead of failing when detects a package is already installed, it will upgrade if the versions don't match, or do nothing (exit 0) if it is considered "up-to-date".cargo install
The following command will always uninstall, download and compile the latest version of the crate - even if there's no newer version available. Under normal circumstances the feature should be preferred as it does save time and bandwidth if there's no new version of the crate.install-upgrade
cargo install --force <crate>
Further information can be found in the GitHub issue rust-lang/cargo#6797 and in the official documentation chapter.
From the guide, will check for updates to itself (in addition to the toolchain updates) every time you run rustup. You could also exclusively update rustup by running rustup update.rustup self update
There is a optional subcommand to do that:cargo-update
cargo install cargo-update
cargo install-update -a
Done.
I've done this by creating a temporary cargo project and adding a small dependency to it. Something like this:
mkdir /tmp/deleteme \
&& cd /tmp/deleteme \
&& cargo init \
&& cargo add serde \
&& rm -rf /tmp/deleteme
You should immediately see the message:
Updating crates.io index