cargo-add(1)

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.

Upon successful invocation, the enabled (+) and disabled (-) features of the specified dependency will be listed in the command's output.

OPTIONS

Source options

Section options

Dependency options

Display Options

Manifest Options

Common Options

ENVIRONMENT

See the reference for details on environment variables that Cargo reads.

EXIT STATUS

  • 0: Cargo succeeded.
  • 101: Cargo failed to complete.

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
    
  5. Add windows as a platform specific dependency on cfg(windows)

    cargo add windows --target 'cfg(windows)'
    

SEE ALSO

cargo(1), cargo-remove(1)