Skip to main content
The cargo module manages Rust packages using cargo, the Rust package manager and build tool.

Functions

packages

Install, remove, or update cargo packages.
str | list[str]
List of packages to ensure.
bool
default:true
Whether the packages should be present.
bool
default:false
Whether to upgrade packages without a specified version.
Package versions can be pinned like cargo: <pkg>@<version>

Common Use Cases

Install Development Tools

Install Command-Line Tools

Install Specific Versions

Update Tools

Remove Tools

Install from Git Repository

Install with Features

Cargo-Specific Tips

Cargo installs binaries to ~/.cargo/bin by default:
Update cargo and rustc:
View installed cargo packages:
Clean cargo’s build cache:
Install with exact dependency versions:
Install for different targets:

Best Practices

Cargo is excellent for installing fast CLI tools:
Here are some popular CLI tools you can install with cargo:

ripgrep

Fast recursive grep alternative

fd-find

Fast and user-friendly find alternative

bat

Cat clone with syntax highlighting

exa

Modern replacement for ls

tokei

Code statistics tool

hyperfine

Command-line benchmarking tool

Important Notes

Installing cargo packages compiles from source, which can take significant time and requires a C compiler and build tools.
Cargo packages are installed to ~/.cargo/bin by default. Ensure this directory is in your PATH.
For faster installations on multiple machines, consider setting up a binary cache or using pre-compiled binaries where available.