Does cargo install have an equivalent update command?
Solution 1
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.
Solution 2
There is no such command in vanilla cargo (well, there's cargo install but that's for dependencies), but since cargo supports third-party subcommands there is an answer: the cargo-update crate.
Install as usual with cargo install cargo-update, then use cargo install-update -a to update all installed packages, for more usage information and examples see the cargo install-update manpage.
Disclaimer: am author
Solution 3
A solution I've found is to add the --force flag to the install command. For example cargo install --force clippy. This will effectively re-install the latest version.
Solution 4
Here is a one-liner to update all installed Cargo crates, except those installed from a local folder:
cargo install $(cargo install --list | egrep '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ')
Explanation:
- List installed packages
- Filter to lines which contain package names and versions, and exclude ones with filesystem paths
- Cut those lines to only include the package name
-
cargo installwith the resulting package names
Solution 5
Nope. You can discuss it in this issue.
Related videos on Youtube
Comments
-
w.brian over 2 yearsI'd like to update a package that I used
cargo installto globally install packages, such as rustfmt or racer. I can't find a way to update an installed package without first deleting it (viacargo uninstall) and then running the install command again. Is there an update command?-
Vladimir Matveev over 7 yearsNope. You can discuss it in this issue.
-
-
Ben Sandeen about 5 yearsThank you so much for this utility! It's fantastic! And this should be the accepted answer
-
набиячлэвэли about 5 years@BenSandeen Well, that's the general treatment answers that are a year late v0v -
rofrol over 4 yearsneedscmaketo be installed -
набиячлэвэли over 4 years@rofrol As is clearly outlaid in the Installation sexion of the Manpage -
Monstieur over 3 yearsWill this also compile them with nightly? -
Rag over 3 yearsThis is now stabilized, and the default behavior. You no longer need to use the nightly channel or provide the-Z install-upgradeargument. github.com/rust-lang/cargo/pull/7560 -
David Bailey over 2 yearsIn recent versions ofcargo, using--forceis no longer necessary to update a crate -
Tom almost 2 yearsIf you wish to update all packages a simple shell command such ascargo install --list | grep '^[a-zA-Z0-9_\-]* v[0-9.]*:$' | cut -d ' ' -f1 | xargs cargo installwould suffice -
Herohtar over 1 yearAutomatic upgrade does not seem to be the default behavior in Rust 1.55.0; I hadwasm-pack 0.10.0installed, but when I tried to update it to0.10.1usingcargo install wasm-packI got an error:error: binary 'wasm-pack' already exists in destinationand had to use--force. -
Illia over 1 yearThank you for an answer without external dependencies. -
leonheess 12 monthsInvalidOperation: Cannot run a document in the middle of a pipeline: C:\Program Files\Git\usr\bin\egrep. error: Using `cargo install` to install the binaries for the package in current working directory is no longer supported, use `cargo install --path .` instead. Use `cargo build` if you want to simply build the package.