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!
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Manually install here.
Note: This installs the whole Rust toolchain including
rustup, and Rust itself.
Compiling from source:
git clone https://github.com/rust-lang/cargo
Note: This installs just cargo
Checking the installation process:
If this command executes, tells you cargo's version, without errors then cargo is successfully installed.
Gives you the current version.
cargo --help [COMMAND]
Shows help message for the command specified.
Shows useful commands as well as a help message.
Lists all the available commands.
Enables verbose output. Use
cargo -vv for more verbose output.
cargo --locked or cargo --frozen
Cargo.lock to be up to date.
cargo --color WHEN
Enables colors: always, auto, or never.
Prevents cargo from accessing the network.
Unstable, nightly-only flags to cargo.
Overrides current toolchain with the toolchain specified (example:
cargo +nightly switches to the nightly toolchain).
cargo new --bin NAME
Creates a new Rust project with the given name.
cargo new --lib NAME
Creates a new Rust library with the given name.
cargo init --bin
Creates a new Rust project in your current directory.
cargo init --lib
Creates a new Rust library in your current directory.
cargo build or cargo b
Builds your Rust project.
cargo run or cargo r
Executes your Rust project.
Executes the benchmarks of your Rust project.
cargo test or cargo t
Executes the tests of your Rust project.
cargo check or cargo c
Checks for errors in your Rust project.
Creates your Rust project documentation (use
cargo doc --open to open it).
Searches for crates on
cargo install CRATE
Installs the specified crate.
cargo install --list
Lists all the crates you installed.
Logs in to your
Manages owners of your crate (add owners by using the
Publishes your crate to
Removes your crate from
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!