3 {{*set actionverb="Add"}}
8 cargo-add --- Add dependencies to a Cargo.toml manifest file
12 `cargo add` [_options_] _crate_...\
13 `cargo add` [_options_] `--path` _path_\
14 `cargo add` [_options_] `--git` _url_ [_crate_...]\
19 This command can add or modify dependencies.
21 The source for the dependency can be specified with:
23 * _crate_`@`_version_: Fetch from a registry with a version constraint of "_version_"
24 * `--path` _path_: Fetch from the specified _path_
25 * `--git` _url_: Pull from a git repo at _url_
27 If no source is specified, then a best effort will be made to select one, including:
29 * Existing dependencies in other tables (like `dev-dependencies`)
31 * Latest release in the registry
33 When you add a package that is already present, the existing entry will be updated with the flags specified.
35 Upon successful invocation, the enabled (`+`) and disabled (`-`) [features] of the specified
36 dependency will be listed in the command's output.
38 [features]: ../reference/features.md
46 {{#option "`--git` _url_" }}
47 [Git URL to add the specified crate from](../reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories).
50 {{#option "`--branch` _branch_" }}
51 Branch to use when adding from git.
54 {{#option "`--tag` _tag_" }}
55 Tag to use when adding from git.
58 {{#option "`--rev` _sha_" }}
59 Specific commit to use when adding from git.
62 {{#option "`--path` _path_" }}
63 [Filesystem path](../reference/specifying-dependencies.html#specifying-path-dependencies) to local crate to add.
66 {{> options-registry }}
74 {{#option "`--dev`" }}
75 Add as a [development dependency](../reference/specifying-dependencies.html#development-dependencies).
78 {{#option "`--build`" }}
79 Add as a [build dependency](../reference/specifying-dependencies.html#build-dependencies).
82 {{#option "`--target` _target_" }}
83 Add as a dependency to the [given target platform](../reference/specifying-dependencies.html#platform-specific-dependencies).
85 To avoid unexpected shell expansions, you may use quotes around each target, e.g., `--target 'cfg(unix)'`.
90 ### Dependency options
94 {{#option "`--dry-run`" }}
95 Don't actually write the manifest
98 {{#option "`--rename` _name_" }}
99 [Rename](../reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml) the dependency.
102 {{#option "`--optional`" }}
103 Mark the dependency as [optional](../reference/features.html#optional-dependencies).
106 {{#option "`--no-optional`" }}
107 Mark the dependency as [required](../reference/features.html#optional-dependencies).
110 {{#option "`--no-default-features`" }}
111 Disable the [default features](../reference/features.html#dependency-features).
114 {{#option "`--default-features`" }}
115 Re-enable the [default features](../reference/features.html#dependency-features).
118 {{#option "`-F` _features_" "`--features` _features_" }}
119 Space or comma separated list of [features to
120 activate](../reference/features.html#dependency-features). When adding multiple
121 crates, the features for a specific crate may be enabled with
122 `package-name/feature-name` syntax. This flag may be specified multiple times,
123 which enables all specified features.
126 {{#option "`--ignore-rust-version`" }}
127 Ignore `rust-version` specification in packages.
129 This option is unstable and available only on the
130 [nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
131 and requires the `-Z unstable-options` flag to enable.
132 See <https://github.com/rust-lang/cargo/issues/5579> for more information.
141 {{> options-display }}
147 {{> options-manifest-path }}
149 {{#option "`-p` _spec_" "`--package` _spec_" }}
150 Add dependencies to only the specified package.
153 {{> options-locked }}
156 {{> section-options-common }}
158 {{> section-environment }}
160 {{> section-exit-status }}
164 1. Add `regex` as a dependency
168 2. Add `trybuild` as a dev-dependency
170 cargo add --dev trybuild
172 3. Add an older version of `nom` as a dependency
176 4. Add support for serializing data structures to json with `derive`s
178 cargo add serde serde_json -F serde/derive
180 5. Add `windows` as a platform specific dependency on `cfg(windows)`
182 cargo add windows --target 'cfg(windows)'
185 {{man "cargo" 1}}, {{man "cargo-remove" 1}}