DEV Community

Henry Boisdequin
Henry Boisdequin

Posted on Edited on

Cargo (Rust Package Manager) Cheatsheet

This is a practical cheat sheet to use when using the Rust package manager Cargo. A package manager allows you to install dependencies, update dependencies, modify your project, configure your project, and more. The best package manager for Rust is Cargo which was built by the Rust core team. Let's get right into the cheatsheet!


Installing and updating Cargo

Mac/Linux:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Windows:

Manually install here.

Note: This installs the whole Rust toolchain including cargo, rustup, and Rust itself.

Compiling from source:

git clone https://github.com/rust-lang/cargo
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Note: This installs just cargo

Checking the installation process:

cargo --version
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

If this command executes, tells you cargo's version, without errors then cargo is successfully installed.


General Usage

cargo --version
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Gives you the current version.

cargo --help [COMMAND]
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Shows help message for the command specified.

cargo
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Shows useful commands as well as a help message.

cargo --list
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Lists all the available commands.

cargo --verbose
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Enables verbose output. Use cargo -vv for more verbose output.

cargo --quiet
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Disable output.

cargo --locked or cargo --frozen
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Requires Cargo.lock to be up to date.

cargo --color WHEN
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Enables colors: always, auto, or never.

cargo --offline
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Prevents cargo from accessing the network.

cargo -z
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Unstable, nightly-only flags to cargo.

cargo +toolchain
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Overrides current toolchain with the toolchain specified (example: cargo +nightly switches to the nightly toolchain).


Creating a new Rust project

cargo new --bin NAME
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Creates a new Rust project with the given name.

cargo new --lib NAME
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Creates a new Rust library with the given name.

cargo init --bin
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Creates a new Rust project in your current directory.

cargo init --lib
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Creates a new Rust library in your current directory.


Using Cargo in your projects

cargo build or cargo b
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Builds your Rust project.

cargo run or cargo r
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Executes your Rust project.

cargo bench
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Executes the benchmarks of your Rust project.

cargo test or cargo t
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Executes the tests of your Rust project.

cargo check or cargo c
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Checks for errors in your Rust project.

cargo doc
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Creates your Rust project documentation (use cargo doc --open to open it).

cargo clean
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Removes the target directory.


Using crates

cargo search
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Searches for crates on crates.io.

cargo install CRATE
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Installs the specified crate.

cargo install --list
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Lists all the crates you installed.


Pushlishing your crate

cargo login
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Logs in to your crates.io account.

cargo owner
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Manages owners of your crate (add owners by using the --add flag).

cargo publish
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Publishes your crate to crates.io.

cargo yank
📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026 📺 Info Siaran: hb/cargo rust package manager cheatsheet - Info Live Streaming 2026

Removes your crate from crates.io.


This is a practical cheatsheet on Cargo! I hope you learned a new command or more about Cargo. If you would like to access this cheatsheet, later on, I would recommend bookmarking this page or adding it to your reading list. Thanks for reading!

Henry

📰 Newsletter
🐱 GitHub
🐦 Twitter

Top comments (0)