Idea: cargo install --update

AFAICT, cargo install presently offers two behaviors:

  • cargo install: will install a bin crate if it isn't installed already. If it is, it errors out saying a binary is already installed, suggesting "Add --force to overwrite"
  • cargo install --force: will always overwrite existing binaries, even if they came from the same version of the same bin crate

This is problematic in CI environments where people would like to cargo install a utility to run as part of their CI pipeline, and leverage the CI environment's built-in caching functionality so subsequent runs can use the previously built binary. It seems in cases like this one of two things happens:

  1. They don't reinstall if the binary is already installed, leaving them stuck on the first version they install. This is fast but leaves them stale.
  2. They add --force, always reinstalling for every run, which is both slow and runs up the bandwidth usage.

I think it'd be great if there were a middle option, which would act like --force, but idempotent for binaries which are installed from the same version of the same crate. That is to say: if you're reinstalling the same binaries from the same crate it's a noop, but if there's a new version of that crate it installs that and overwrites the previous version.

Something like:

cargo install --update cargo-audit

Relevant cargo-audit issue:


This is already supported on nightly behind a feature flag.


Oh neat! Thanks for the pointer

Fully agreed! When can we make that cargo feature stable? :smiley:

1 Like