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:

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

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

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)