commands.sh

cargo

all

Manage Rust projects and their module dependencies (crates). Some subcommands such as `build` have their own usage documentation.

More info →

Subcommands (38)

cargo add

Add dependencies to a Rust project's `Cargo.toml` manifest.

cargo bench

Compile and execute benchmarks.

cargo binstall

Install Rust binaries from CI artifacts. Falls back to `cargo install` (from source code) if there are no binaries available.

cargo build

Compile a local package and all of its dependencies.

cargo check

Check a local package and all of its dependencies for errors.

cargo clean

Remove generated artifacts in the `target` directory.

cargo clippy

A collection of lints to catch common mistakes and improve your Rust code.

cargo deb

Create Debian packages from Cargo projects.

cargo doc

Build the documentation of Rust packages.

cargo fetch

Fetch dependencies of a package from the network.

cargo fix

Automatically fix lint warnings reported by `rustc`.

cargo fmt

Run `rustfmt` on all source files in a Rust project.

cargo help

Display help on `cargo` and its subcommands.

cargo info

Display information about a Rust package.

cargo init

Create a new Cargo package. Equivalent of `cargo new`, but specifying a directory is optional.

cargo install

Build and install a Rust binary.

cargo login

Save an API token from the registry locally. The token is used to authenticate to a package registry. You can remove it using `cargo logout`.

cargo logout

Remove an API token from the registry locally. The token is used to authenticate to a package registry. You can add it back using `cargo login`.

cargo metadata

Output the workspace members and resolved dependencies of current package as JSON. Note: The output format is subject to change in future versions of Cargo.

cargo msrv

Manage the Minimum Supported Rust Version (MSRV) of a project.

cargo new

Create a new Cargo package. Equivalent of `cargo init`, but specifying a directory is required.

cargo owner

Manage the owners of a crate on the registry.

cargo package

Assemble a local package into a distributable tarball (a `.crate` file). Similar to `cargo publish --dry-run`, but has more options.

cargo pkgid

Print the fully qualified package ID specifier for a package or dependency in the current workspace.

cargo publish

Upload a package to a registry. Note: You have to add an authentication token using `cargo login` before publishing a package.

cargo remove

Remove dependencies from a Rust project's `Cargo.toml` manifest.

cargo report

Display various kinds of reports.

cargo run

Run the current Cargo package. Note: The working directory of the executed binary will be set to the current working directory.

cargo rustc

Compile a Rust package. Similar to `cargo build`, but you can pass extra options to the compiler. See `rustc --help` for all available options.

cargo rustdoc

Build the documentation of Rust packages. Similar to `cargo doc`, but you can pass options to `rustdoc`. See `rustdoc --help` for all available options.

cargo search

Search for packages on <https://crates.io>. The crates are displayed along with descriptions in TOML format suitable for copying into `Cargo.toml`.

cargo test

Execute the unit and integration tests of a Rust package.

cargo tree

Display a tree visualization of a dependency graph. Note: In the tree, dependencies of packages marked with `(*)` have already been shown elsewhere in the graph, and so are not repeated.

cargo uninstall

Remove a Rust binary installed globally using `cargo install`.

cargo update

Update dependencies as recorded in `Cargo.lock`.

cargo vendor

Vendor all dependencies of a project into the specified directory (default: `vendor`).

cargo version

Display `cargo` version information.

cargo yank

Remove a pushed crate from the index. This should only be used when you accidentally release a significantly broken crate. Note: This does not remove any data. The crate is still present after a yank - this just prevents new projects from using it.

Options (3)

boolean

Build the Rust project in the current directory using the release profile

Example: cargo {{[b|build]}} {{[-r|--release]}}
-r, --releaseboolean

Build the Rust project in the current directory using the release profile

Example: cargo {{[b|build]}} {{[-r|--release]}}
-j, --jobsboolean

Build using a specific number of threads (default is the number of logical CPUs)

Example: cargo {{[b|build]}} {{[-j|--jobs]}} {{number_of_threads}}

Examples (8)

Search for crates

cargo search search_string

Install a binary crate

cargo install crate_name

List installed binary crates

Create a new binary or library Rust project in the specified directory (or the current working directory by default)

cargo init --bin|lib path/to/directory

Add a dependency to `Cargo.toml` in the current directory

cargo add dependency

Build the Rust project in the current directory using the release profile

cargo [b|build] [-r|--release]

Build the Rust project in the current directory using the nightly compiler (requires `rustup`)

cargo +nightly [b|build]

Build using a specific number of threads (default is the number of logical CPUs)

cargo [b|build] [-j|--jobs] number_of_threads
made by @shridhargupta | data from tldr-pages