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
Installation Location
Installation Location
Cargo installs binaries to
~/.cargo/bin by default:Update Cargo Itself
Update Cargo Itself
Update cargo and rustc:
List Installed Packages
List Installed Packages
View installed cargo packages:
Clean Build Cache
Clean Build Cache
Clean cargo’s build cache:
Install with Locked Dependencies
Install with Locked Dependencies
Install with exact dependency versions:
Cross-Compilation
Cross-Compilation
Install for different targets:
Best Practices
Install Rust First
Install Rust First
Use for CLI Tools
Use for CLI Tools
Cargo is excellent for installing fast CLI tools:
Keep Tools Updated
Keep Tools Updated
Popular Rust 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
Cargo packages are installed to
~/.cargo/bin by default. Ensure this directory is in your PATH.