Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does cargo install have an equivalent update command?

I'd like to update a package that I used cargo install to globally install packages, such as rustfmt or racer. I can't find a way to update an installed package without first deleting it (via cargo uninstall) and then running the install command again. Is there an update command?

like image 716
w.brian Avatar asked Dec 27 '15 20:12

w.brian


People also ask

Where are cargo binaries installed?

All binaries installed with cargo install are stored in the installation root's bin folder. If you installed Rust using rustup.rs and don't have any custom configurations, this directory will be $HOME/. cargo/bin. Ensure that directory is in your $PATH to be able to run programs you've installed with cargo install .

How do you install cargo?

The easiest way to get Cargo is to install the current stable release of Rust by using rustup. Installing Rust using rustup will also install cargo . It will download a script, and start the installation.


2 Answers

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

like image 156
набиячлэвэли Avatar answered Oct 09 '22 00:10

набиячлэвэли


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.

like image 31
Nicolai Fröhlich Avatar answered Oct 08 '22 23:10

Nicolai Fröhlich