2 {{*set actionverb="Add"}}
7 cargo-add - Add dependencies to a Cargo.toml manifest file
11 `cargo add` [_options_] _crate_...\
12 `cargo add` [_options_] `--path` _path_\
13 `cargo add` [_options_] `--git` _url_ [_crate_...]\
18 This command can add or modify dependencies.
20 The source for the dependency can be specified with:
22 * _crate_`@`_version_: Fetch from a registry with a version constraint of "_version_"
23 * `--path` _path_: Fetch from the specified _path_
24 * `--git` _url_: Pull from a git repo at _url_
26 If no source is specified, then a best effort will be made to select one, including:
28 * Existing dependencies in other tables (like `dev-dependencies`)
30 * Latest release in the registry
32 When you add a package that is already present, the existing entry will be updated with the flags specified.
34 Upon successful invocation, the enabled (`+`) and disabled (`-`) [features] of the specified
35 dependency will be listed in the command's output.
37 [features]: ../reference/features.md
45 {{#option "`--git` _url_" }}
46 [Git URL to add the specified crate from](../reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories).
49 {{#option "`--branch` _branch_" }}
50 Branch to use when adding from git.
53 {{#option "`--tag` _tag_" }}
54 Tag to use when adding from git.
57 {{#option "`--rev` _sha_" }}
58 Specific commit to use when adding from git.
61 {{#option "`--path` _path_" }}
62 [Filesystem path](../reference/specifying-dependencies.html#specifying-path-dependencies) to local crate to add.
65 {{> options-registry }}
73 {{#option "`--dev`" }}
74 Add as a [development dependency](../reference/specifying-dependencies.html#development-dependencies).
77 {{#option "`--build`" }}
78 Add as a [build dependency](../reference/specifying-dependencies.html#build-dependencies).
81 {{#option "`--target` _target_" }}
82 Add as a dependency to the [given target platform](../reference/specifying-dependencies.html#platform-specific-dependencies).
90 ### Dependency options
94 {{#option "`--rename` _name_" }}
95 [Rename](../reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml) the dependency.
98 {{#option "`--optional`" }}
99 Mark the dependency as [optional](../reference/features.html#optional-dependencies).
102 {{#option "`--no-optional`" }}
103 Mark the dependency as [required](../reference/features.html#optional-dependencies).
106 {{#option "`--no-default-features`" }}
107 Disable the [default features](../reference/features.html#dependency-features).
110 {{#option "`--default-features`" }}
111 Re-enable the [default features](../reference/features.html#dependency-features).
114 {{#option "`--features` _features_" }}
115 Space or comma separated list of [features to
116 activate](../reference/features.html#dependency-features). When adding multiple
117 crates, the features for a specific crate may be enabled with
118 `package-name/feature-name` syntax. This flag may be specified multiple times,
119 which enables all specified features.
128 {{> options-display }}
134 {{> options-manifest-path }}
137 {{> section-options-common }}
139 {{> section-environment }}
141 {{> section-exit-status }}
145 1. Add `regex` as a dependency
149 2. Add `trybuild` as a dev-dependency
151 cargo add --dev trybuild
153 3. Add an older version of `nom` as a dependency
157 4. Add support for serializing data structures to json with `derive`s
159 cargo add serde serde_json -F serde/derive