rustrust-cargo

Does cargo install have an equivalent update command?


I used cargo install to globally install a package, such as rustfmt or racer.

How can I update the installed package without first deleting it ( cargo uninstall) and then running cargo install again.

Is there an update command?


Solution

  • 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).

    How does it work?

    Instead of failing when cargo install 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".

    Forcing an upgrade / re-installation

    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 install-upgrade feature should be preferred as it does save time and bandwidth if there's no new version of the crate.

    cargo install --force <crate>
    

    Documentation

    Further information can be found in the GitHub issue rust-lang/cargo#6797 and in the official documentation chapter.