CARGO-ADD(1)
πΈ CARGO-ADD(1) β the cargo add page, but make it a group chat πΈ
okay so this is the manual page for cargo-add, straight out of the General Commands Manual section of the Cargo docs. it's the one that puts dependencies into your Cargo.toml manifest file. bestie, it's literally the "hey can you come through" of commands. π
β¨ 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. yes, modify too β it's giving main character energy, it does both. π
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's already present, the existing entry will be updated with the flags specified. no dupe, just glow-up. β¨
upon successful invocation, the enabled (+) and disabled (-) features β https://doc.rust-lang.org/cargo/reference/features.html β of the specified dependency will be listed in the command's output. so you get receipts. π§Ύ
π OPTIONS π
π Source options
--git urlβ Git URL to add the specified crate from βhttps://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories--branch branchβ branch to use when adding from git--tag tagβ tag to use when adding from git--rev shaβ specific commit to use when adding from git--path pathβ filesystem path to the local crate to add βhttps://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-path-dependencies--registry registryβ name of the registry to use. registry names are defined in Cargo config files βhttps://doc.rust-lang.org/cargo/reference/config.html. if not specified, the default registry is used, which is defined by theregistry.defaultconfig key, which defaults tocrates-io.
π Section options
--devβ add as a development dependency βhttps://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies--buildβ add as a build dependency βhttps://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#build-dependencies--target targetβ add as a dependency to the given target platform βhttps://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies
to avoid unexpected shell expansions, you may use quotes around each target, e.g., --target 'cfg(unix)'. yes bestie, the quotes are load-bearing, do not skip them π
π Dependency options
--dry-runβ don't actually write the manifest. window shopping only, no cap ποΈ--rename nameβ rename the dependency βhttps://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml--optionalβ mark the dependency as optional βhttps://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies--no-optionalβ mark the dependency as required βhttps://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies--publicβ mark the dependency as public.
the dependency can be referenced in your library's public API.
Unstable (nightly-only) β https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency
--no-publicβ mark the dependency as private.
while you can use the crate in your implementation, it cannot be referenced in your public API.
Unstable (nightly-only) β https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency
--no-default-featuresβ disable the default features βhttps://doc.rust-lang.org/cargo/reference/features.html#dependency-features--default-featuresβ re-enable the default features βhttps://doc.rust-lang.org/cargo/reference/features.html#dependency-features-F features,--features featuresβ space or comma separated list of features to activate βhttps://doc.rust-lang.org/cargo/reference/features.html#dependency-features. when adding multiple crates, the features for a specific crate may be enabled withpackage-name/feature-namesyntax. this flag may be specified multiple times, which enables all specified features. (yes, stack it up π )--ignore-rust-versionβ ignorerust-versionspecification in packages.
this option is unstable and available only on the nightly channel βhttps://doc.rust-lang.org/book/appendix-07-nightly-rust.htmlβ and requires the-Z unstable-optionsflag to enable. seehttps://github.com/rust-lang/cargo/issues/5579for more information.
π₯ Display Options
-v,--verboseβ use verbose output. may be specified twice for βvery verboseβ output, which includes extra output such as dependency warnings and build script output. may also be specified with theterm.verboseconfig value βhttps://doc.rust-lang.org/cargo/reference/config.html-q,--quietβ do not print cargo log messages. may also be specified with theterm.quietconfig value βhttps://doc.rust-lang.org/cargo/reference/config.html--color whenβ control when colored output is used. valid values:auto(default): automatically detect if color support is available on the terminal.always: always display colors.never: never display colors.
may also be specified with the term.color config value β https://doc.rust-lang.org/cargo/reference/config.html
π Manifest Options
--manifest-path pathβ path to theCargo.tomlfile. by default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory.-p spec,--package specβ add dependencies to only the specified package.--frozen,--lockedβ either of these flags requires that theCargo.lockfile is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error. the--frozenflag also prevents Cargo from attempting to access the network to determine if it is out-of-date.
these may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access.
--offlineβ prevents Cargo from accessing the network for any reason. without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. with this flag, Cargo will attempt to proceed without the network if possible.
beware that this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. see the cargo-fetch(1) command to download dependencies before going offline. π
may also be specified with the net.offline config value β https://doc.rust-lang.org/cargo/reference/config.html
β Common Options
+toolchainβ if Cargo has been installed with rustup, and the first argument to cargo begins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). see the rustup documentation βhttps://rust-lang.github.io/rustup/overrides.htmlβ for more information about how toolchain overrides work.--config KEY=VALUE or PATHβ overrides a Cargo configuration value. the argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. this flag may be specified multiple times. see the command-line overrides section βhttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesβ for more information.-C PATHβ changes the current working directory before executing any specified operations. this affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. this option must appear before the command name, for examplecargo -C path/to/my-project build.
this option is only available on the nightly channel βhttps://doc.rust-lang.org/book/appendix-07-nightly-rust.htmlβ and requires the-Z unstable-optionsflag to enable (see #10098 βhttps://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information.-Z flagβ unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details.
π§ ENVIRONMENT π§
see the reference β https://doc.rust-lang.org/cargo/reference/environment-variables.html β for details on environment variables that Cargo reads. π
π EXIT STATUS π
0: Cargo succeeded. slay β¨101: Cargo failed to complete. π
π«Ά EXAMPLES π«Ά
- add
regexas a dependency
cargo add regex
- add
trybuildas a dev-dependency
cargo add --dev trybuild
- add an older version of
nomas a dependency
cargo add nom@5
- add support for serializing data structures to json with derives
cargo add serde serde_json -F serde/derive
- add
windowsas a platform specific dependency oncfg(windows)
cargo add windows --target 'cfg(windows)'
π SEE ALSO π
and that's the whole page, bestie π it's CARGO-ADD(1) from the Cargo General Commands Manual β the cargo-add page itself, exactly as it lives in the docs. no cap, every flag accounted for, periodt. π
π¦ where this page comes from
- ubuntu jammy: cargo-1.78 1.78.0+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.78 1.78.0+dfsg1ubuntu1-0ubuntu0.24.04.2 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms