Skip to content
Latchkey

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

FlagEffect
--devRemove from dev-dependencies
--buildRemove from build-dependencies
-p, --package <m>Target a workspace member

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →