LinuxCommandLibrary

cargo-add

Add dependencies to a Rust project

TLDR

Add dependency

$ cargo add [serde]
copy
Add with specific version
$ cargo add [serde@1.0]
copy
Add with features
$ cargo add [tokio] --features [full]
copy
Add as dev dependency
$ cargo add [mockall] --dev
copy
Add as build dependency
$ cargo add [cc] --build
copy
Add from git repository
$ cargo add --git [https://github.com/user/repo]
copy
Add from local path
$ cargo add --path [../my-crate]
copy
Add as optional dependency
$ cargo add [feature-crate] --optional
copy
Rename dependency
$ cargo add [serde] --rename [my_serde]
copy

SYNOPSIS

cargo add [options] crate...
cargo add [options] --path path
cargo add [options] --git url [crate...]

DESCRIPTION

cargo add adds or modifies dependencies in Cargo.toml. It fetches crate information from the registry and updates the manifest with the correct version constraints. Built into Cargo since v1.62.

PARAMETERS

--dev, -D

Add as development dependency
--build, -B
Add as build dependency
--optional
Mark dependency as optional
--rename name
Rename the dependency
--features features
Enable specific features
--no-default-features
Disable default features
--default-features
Re-enable default features
--path path
Add dependency from local path
--git url
Add dependency from git repository
--branch branch
Git branch to use
--tag tag
Git tag to use
--rev sha
Git commit to use
-p, --package spec
Package to modify
--dry-run
Show changes without modifying files

OUTPUT

Lists enabled (+) and disabled (-) features of added dependencies.

CAVEATS

Updates existing entries with specified flags. For Cargo versions before 1.62, install cargo-edit for this functionality.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community