cargo remove: Usage, Options & Common CI Errors
Remove a dependency from your manifest.
cargo remove deletes a dependency entry from Cargo.toml. It is the inverse of cargo add and operates on the same dependency tables.
What it does
Strips the named dependency from the chosen table in Cargo.toml. It does not by itself touch Cargo.lock until the next resolve (build, check, or generate-lockfile).
Common usage
Terminal
cargo remove serde # from [dependencies]
cargo remove --dev assert_cmd # from [dev-dependencies]
cargo remove --build cc # from [build-dependencies]Common CI error: dependency not found
cargo remove foo fails with "error: the dependency foo could not be found in dependencies" when it actually lives in dev- or build-dependencies. Fix: pass the matching table flag (--dev or --build). After removing, run cargo build to refresh Cargo.lock so the dropped crate leaves the lockfile.
Options
| Flag | Effect |
|---|---|
| --dev | Remove from dev-dependencies |
| --build | Remove from build-dependencies |
| -p, --package <m> | Target a workspace member |
Related guides
cargo add: Usage, Options & Common CI Errorscargo add edits Cargo.toml to add a dependency, with --features, --dev, and --optional. Learn the syntax and…
cargo update: Usage, Options & Common CI Errorscargo update changes Cargo.lock to newer dependency versions. Learn -p to update one crate, --precise to pin,…
cargo tree: Usage, Options & Common CI Errorscargo tree prints your dependency graph. Learn -i to find who pulls in a crate, -d for duplicates, and how to…