A Better Cargo Install Workflow
How I manage to keep the tools I've installed with cargo up-to-date
Thanks to great tooling in the ecosystem, people are constantly building really great CLI tools with Rust. And with cargo
it is really easy to install and distribute them, without the author needing to go through the hassle of integrating it into yet another package manager. Everything is a cargo install
away.
However, there are a few downsides:
- Do I really have to build them from source every single time? (for some tools, while it is amazing
cargo
makes it easy, it still takes a long time) - How do I keep track of all of the CLIs I have installed? And keep them up-to-date?
I've managed to address both with a two cargo subcommands.
cargo binstall
: Fast installs from pre-built binaries
cargo-binstall is in most cases a drop-in replacement for cargo install
. It has a multi-tiered strategy to find binaries already compiled for your target architecture, falling back to building from source if it can't find one.
9 times out of 10, this means installing takes mere seconds (instead of minutes).
To get started, there are several methods of installation, and if you use the shell script, it will already use cargo-binstall to install cargo-binstall. But you can also do a plain cargo install
(and this will hopefully be the last time you have to do this).
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
Linux and Mac
Set-ExecutionPolicy Unrestricted -Scope Process; iex (iwr "https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.ps1").Content
Windows
cargo install cargo-binstall
Or plain cargo install
Once this is done, you can now use cargo binstall
and get faster installs! Try it out. (If you need an idea, cargo-nextest is one I recommend to everyone).
cargo install-update -a
to update all of your installed binaries
Now that you can install all of the binaries you want quickly, you may want to keep them up-to-date and get all of their new features as quickly as possible as well.
Thanks to the cargo-update subcommand, this is really easy. First, install the command:
cargo binstall cargo-update
Which should go quickly with binstall!
Then, you can just run:
cargo install-update -a
This will go through and check all of your cargo installed binaries and see if there are newer versions. Since you have cargo-binstall
installed, it will default to using this, which makes the upgrades quick and painless, only needing to cargo install
from source if binstall can't install it for you.
Polling registry 'https://index.crates.io/'.................
Package Installed Latest Needs update
cargo-binstall v1.10.10 v1.10.11 Yes
wasmtime-cli v26.0.0 v26.0.1 Yes
cargo-component v0.18.0 v0.18.0 No
cargo-expand v1.0.95 v1.0.95 No
cargo-insta v1.41.1 v1.41.1 No
cargo-machete v0.7.0 v0.7.0 No
cargo-msrv v0.16.2 v0.16.2 No
cargo-nextest v0.9.82 v0.9.82 No
cargo-outdated v0.15.0 v0.15.0 No
cargo-update v16.0.0 v16.0.0 No
flamegraph v0.6.5 v0.6.5 No
maturin v1.7.4 v1.7.4 No
sqlx-cli v0.8.2 v0.8.2 No
wac-cli v0.6.1 v0.6.1 No
wasm-pack v0.13.1 v0.13.1 No
wasm-tools v1.219.1 v1.219.1 No
wit-deps-cli v0.4.0 v0.4.0 No
Updating cargo-binstall
INFO resolve: Resolving package: 'cargo-binstall'
INFO resolve: Verified signature for package 'cargo-binstall': gh=cargo-bins/cargo-binstall git=02e9225fbd07c965123a530da9d6f5c494e1e977 ts=2024-11-05T21:00:47.717Z run=11692328231
WARN The package cargo-binstall v1.10.11 (aarch64-apple-darwin) has been downloaded from github.com
INFO This will install the following binaries:
INFO - cargo-binstall => /Users/benjamin.brandt/.cargo/bin/cargo-binstall
INFO Installing binaries...
INFO Done in 3.699568708s
Updating wasmtime-cli
INFO resolve: Resolving package: 'wasmtime-cli'
WARN The package wasmtime-cli v26.0.1 (aarch64-apple-darwin) has been downloaded from github.com
INFO This will install the following binaries:
INFO - wasmtime => /Users/benjamin.brandt/.cargo/bin/wasmtime
INFO Installing binaries...
INFO Done in 3.733854125s
Updated 2 packages.
Overall updated 2 packages: cargo-binstall, wasmtime-cli.
Example output. Yes, I do indeed have a lot of installed binaries, but they are all up-to-date!
Also notice that it will even keep cargo-binstall
and cargo-update
up-to-date for you!
And that is it. With this setup, I am no longer worried when using cargo to install tools for me that I'll forget about them and they'll be out of date. The wealth of tools available on crates.io are as easy to use as something from homebrew, and they install in a matter of seconds.
Hopefully this helps enable you to do the same, and enjoy all of the great CLI tooling available to you.