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