List of Rust Cargo Commands


Cargo is the Package Manager as well as the Built Tool for the Rust Programming Language.

So, you will need to make use of cargo commands on a day-to-day basis if you work with Rust.

Sr. No.CommandDescription
1cargo new <project-name>To create a new Cargo package with the specified name.
2cargo bAlias for cargo build.
3cargo runTo build and run the current package.
4cargo testTo run the tests for the current package.
5cargo dAlias for cargo doc.
6cargo updateTo update the dependencies of the current package.
7cargo cleanTo remove artifacts that Cargo has generated in the past.
8cargo publishTo publish the current package to the crates.io registry.
9cargo install <crate>To install the specified crate from crates.io.
10cargo uninstall <crate>To uninstall the specified crate.
11cargo checkTo check a local package and all of its dependencies for errors.
12cargo fmtTo format the source code in the current package according to the project's style guidelines.
13cargo benchTo run the benchmarks defined in the current package.
14cargo build --releaseTo build the current package with optimizations for release.
15cargo run -- <args>To run the current package with the specified command-line arguments.
16cargo build --target <target>To build the current package for the specified target.
17cargo doc --openTo generate documentation and open it in the default browser.
18cargo loginTo log in to the crates.io registry.
19cargo logoutTo log out from the crates.io registry.
20cargo search <crate>To search for crates with the specified name on crates.io.
21cargo metadataTo display the metadata about the current package and its dependencies.
22cargo --versionTo print the version of Cargo.
23cargo --helpTo display help information about Cargo and its commands.
24cargo addTo add dependencies to a Cargo.toml manifest file.
25cargo fixTo automatically fix lint warnings reported by rustc.
26cargo generate-lockfileTo generate the lockfile for a package.
27cargo initTo create a new cargo package in an existing directory.
28cargo locate-projectTo print a JSON representation of a Cargo.toml file's location.
29cargo packageTo assemble the local package into a distributable tarball.
30cargo publishTo upload a package to the registry.
31cargo read-manifestTo print a JSON representation of a Cargo.toml manifest.
32cargo removeTo remove dependencies from a Cargo.toml manifest file.
33cargo rmAlias for cargo remove.
34cargo rustcTo compile a package, and pass extra options to the compiler.
35cargo rustdocTo build a package's documentation, using specified custom flags.
36cargo searchTo search packages in crates.io.
37cargo tAlias for cargo test.
38cargo treeTo display a tree visualization of a dependency graph.
39cargo uninstallTo remove a Rust binary.
40cargo updateTo update dependencies as recorded in the local lock file.
41cargo verify-projectTo check the correctness of a crate manifest.
42cargo versionTo show version information.
43cargo yankTo remove a pushed crate from the index.

The cargo --help and cargo --list are the two commands that can help you know all the installed cargo commands.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap