cargo-add(1)

{{*set actionverb=“Add”}} {{*set nouns=“adds”}}

NAME

cargo-add - Add dependencies to a Cargo.toml manifest file

SYNOPSIS

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

DESCRIPTION

This command can add or modify dependencies.

The source for the dependency can be specified with:

  • crate@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 url

If no source is specified, then a best effort will be made to select one, including:

  • Existing dependencies in other tables (like dev-dependencies)
  • Workspace members
  • Latest release in the registry

When you add a package that is already present, the existing entry will be updated with the flags specified.

OPTIONS

Source 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}}

{{> options-registry }}

{{/options}}

Section 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. {{/option}}

{{/options}}

Dependency options

{}

{{#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 “--no-default-features” }} Disable the default features. {{/option}}

{{#option “--default-features” }} Re-enable the default features. {{/option}}

{{#option “--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}}

Display Options

{} {{> options-display }} {{/options}}

Manifest Options

{} {{> options-manifest-path }} {{/options}}

{{> section-options-common }}

{{> section-environment }}

{{> section-exit-status }}

EXAMPLES

  1. Add regex as a dependency

    cargo add regex
    
  2. Add trybuild as a dev-dependency

    cargo add --dev trybuild
    
  3. Add an older version of nom as a dependency

    cargo add nom@5
    
  4. Add support for serializing data structures to json with derives

    cargo add serde serde_json -F serde/derive
    

SEE ALSO

{{man “cargo” 1}}