src/doc/man/cargo-add.md
{{*set command="add"}}
{{set actionverb="Add"}}
{{~set nouns="adds"}}
cargo-add --- Add dependencies to a Cargo.toml manifest file
cargo add [options] crate...
cargo add [options] --path path
cargo add [options] --git url [crate...]
This command can add or modify dependencies.
The source for the dependency can be specified with:
@version: Fetch from a registry with a version constraint of "version"--path path: Fetch from the specified path--git url: Pull from a git repo at urlIf no source is specified, then a best effort will be made to select one, including:
dev-dependencies)When you add a package that is already present, the existing entry will be updated with the flags specified.
Upon successful invocation, the enabled (+) and disabled (-) features of the specified
dependency will be listed in the command's output.
{{#options}}
{{#option "--git url" }}
Git URL to add the specified crate from.
{{/option}}
{{#option "--branch branch" }}
Branch to use when adding from git.
{{/option}}
{{#option "--tag tag" }}
Tag to use when adding from git.
{{/option}}
{{#option "--rev sha" }}
Specific commit to use when adding from git.
{{/option}}
{{#option "--path path" }}
Filesystem path to local crate to add.
{{/option}}
{{#option "--base base" }}
The path base to use when adding a local crate.
Unstable (nightly-only) {{/option}}
{{> options-registry }}
{{/options}}
{{#options}}
{{#option "--dev" }}
Add as a development dependency.
{{/option}}
{{#option "--build" }}
Add as a build dependency.
{{/option}}
{{#option "--target target" }}
Add as a dependency to the given target platform.
To avoid unexpected shell expansions, you may use quotes around each target, e.g., --target 'cfg(unix)'.
{{/option}}
{{/options}}
{{#options}}
{{#option "--dry-run" }}
Don't actually write the manifest
{{/option}}
{{#option "--rename name" }}
Rename the dependency.
{{/option}}
{{#option "--optional" }}
Mark the dependency as optional.
{{/option}}
{{#option "--no-optional" }}
Mark the dependency as required.
{{/option}}
{{#option "--public" }}
Mark the dependency as public.
The dependency can be referenced in your library's public API.
Unstable (nightly-only) {{/option}}
{{#option "--no-public" }}
Mark the dependency as private.
While you can use the crate in your implementation, it cannot be referenced in your public API.
Unstable (nightly-only) {{/option}}
{{#option "--no-default-features" }}
Disable the default features.
{{/option}}
{{#option "--default-features" }}
Re-enable the default features.
{{/option}}
{{#option "-F features" "--features features" }}
Space or comma separated list of features to
activate. When adding multiple
crates, the features for a specific crate may be enabled with
package-name/feature-name syntax. This flag may be specified multiple times,
which enables all specified features.
{{/option}}
{{/options}}
{{#options}} {{> options-display }} {{/options}}
{{#options}} {{> options-manifest-path }}
{{#option "-p spec" "--package spec" }}
Add dependencies to only the specified package.
{{/option}}
{{> options-ignore-rust-version }}
{{> options-locked }}
{{/options}}
{{> section-options-common }}
{{> section-environment }}
{{> section-exit-status }}
Add regex as a dependency
cargo add regex
Add trybuild as a dev-dependency
cargo add --dev trybuild
Add an older version of nom as a dependency
cargo add nom@5
Add support for serializing data structures to json with derives
cargo add serde serde_json -F serde/derive
Add windows as a platform specific dependency on cfg(windows)
cargo add windows --target 'cfg(windows)'
{{man "cargo" 1}}, {{man "cargo-remove" 1}}