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. | Command | Description |
|---|---|---|
| 1 | cargo new <project-name> | To create a new Cargo package with the specified name. |
| 2 | cargo b | Alias for cargo build. |
| 3 | cargo run | To build and run the current package. |
| 4 | cargo test | To run the tests for the current package. |
| 5 | cargo d | Alias for cargo doc. |
| 6 | cargo update | To update the dependencies of the current package. |
| 7 | cargo clean | To remove artifacts that Cargo has generated in the past. |
| 8 | cargo publish | To publish the current package to the crates.io registry. |
| 9 | cargo install <crate> | To install the specified crate from crates.io. |
| 10 | cargo uninstall <crate> | To uninstall the specified crate. |
| 11 | cargo check | To check a local package and all of its dependencies for errors. |
| 12 | cargo fmt | To format the source code in the current package according to the project's style guidelines. |
| 13 | cargo bench | To run the benchmarks defined in the current package. |
| 14 | cargo build --release | To build the current package with optimizations for release. |
| 15 | cargo run -- <args> | To run the current package with the specified command-line arguments. |
| 16 | cargo build --target <target> | To build the current package for the specified target. |
| 17 | cargo doc --open | To generate documentation and open it in the default browser. |
| 18 | cargo login | To log in to the crates.io registry. |
| 19 | cargo logout | To log out from the crates.io registry. |
| 20 | cargo search <crate> | To search for crates with the specified name on crates.io. |
| 21 | cargo metadata | To display the metadata about the current package and its dependencies. |
| 22 | cargo --version | To print the version of Cargo. |
| 23 | cargo --help | To display help information about Cargo and its commands. |
| 24 | cargo add | To add dependencies to a Cargo.toml manifest file. |
| 25 | cargo fix | To automatically fix lint warnings reported by rustc. |
| 26 | cargo generate-lockfile | To generate the lockfile for a package. |
| 27 | cargo init | To create a new cargo package in an existing directory. |
| 28 | cargo locate-project | To print a JSON representation of a Cargo.toml file's location. |
| 29 | cargo package | To assemble the local package into a distributable tarball. |
| 30 | cargo publish | To upload a package to the registry. |
| 31 | cargo read-manifest | To print a JSON representation of a Cargo.toml manifest. |
| 32 | cargo remove | To remove dependencies from a Cargo.toml manifest file. |
| 33 | cargo rm | Alias for cargo remove. |
| 34 | cargo rustc | To compile a package, and pass extra options to the compiler. |
| 35 | cargo rustdoc | To build a package's documentation, using specified custom flags. |
| 36 | cargo search | To search packages in crates.io. |
| 37 | cargo t | Alias for cargo test. |
| 38 | cargo tree | To display a tree visualization of a dependency graph. |
| 39 | cargo uninstall | To remove a Rust binary. |
| 40 | cargo update | To update dependencies as recorded in the local lock file. |
| 41 | cargo verify-project | To check the correctness of a crate manifest. |
| 42 | cargo version | To show version information. |
| 43 | cargo yank | To 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.
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!