cargo-remove
Remove dependencies from a Cargo.toml manifest
TLDR
Remove a dependency from the current project
Remove a development or build dependency
Remove a dependency of the given target platform
SYNOPSIS
cargo remove [OPTIONS]
PARAMETERS
Required. One or more names of crates to remove from dependencies.
--dev
Remove from [dev-dependencies] section instead of the default [dependencies].
--build
Remove from [build-dependencies] section instead of the default [dependencies].
--target
Remove from target-specific dependencies (e.g., --target x86_64-unknown-linux-gnu).
-p, --package
Package to remove the dependency from. This is useful in a workspace to specify which member package should be modified.
--workspace
Remove the dependency from the workspace root's Cargo.toml, if applicable.
--manifest-path
Path to the Cargo.toml file. By default, Cargo searches for Cargo.toml in the current directory or its parent directories.
--dry-run
Perform a 'dry run' of the command. Don't actually write any changes to disk, but print what would happen.
--verbose, -v
Use verbose output.
--quiet, -q
Do not print cargo log messages.
--color
Control when colors are used in output. Possible values: auto, always, never.
--frozen
Require Cargo.lock and cache are up to date.
--locked
Require Cargo.lock is up to date.
--offline
Run without accessing the network.
DESCRIPTION
cargo remove is a subcommand of the Rust package manager, Cargo, used to remove dependencies from a Rust project's Cargo.toml manifest file.
When executed, it automatically updates the [dependencies] section (or [dev-dependencies], [build-dependencies], or target-specific sections if specified) by deleting the entry for the specified crate(s).
It also updates the Cargo.lock file to reflect the change, ensuring consistency. This command streamlines dependency management, making it easy to unregister unneeded libraries from your project.
It operates on the active package by default or can be directed to a specific package or workspace using options.
CAVEATS
Modifies your project's Cargo.toml and Cargo.lock files directly. Always consider version control before making significant changes.
This command only removes the dependency entry from the manifest. It does not delete cached crate data from your local Cargo registry or the target directory. Use cargo clean to remove compiled artifacts.
If the removed dependency is still referenced in your code, your project will fail to compile. Ensure all usages are also removed.
Removing a dependency might implicitly remove other dependencies that only that crate pulled in, potentially affecting the build graph.
MULTIPLE CRATES
You can specify multiple crate names to remove them in a single command, e.g., cargo remove serde reqwest.
VERSION SPECIFICITY
cargo remove operates on the crate name only. It does not require or allow specifying a version number, as it removes the entire dependency entry for that crate from the manifest.
HISTORY
The functionality of cargo remove was originally provided by an external cargo subcommand, cargo-edit (specifically its cargo rm subcommand). This external tool was widely adopted due to its convenience.
Recognizing the utility and common need for direct dependency management, the remove subcommand was officially integrated into the core Cargo toolchain itself, starting with Rust 1.62.0 (released June 30, 2022). This integration significantly improved its accessibility and solidified its status as a core Cargo feature.
SEE ALSO
cargo(1), cargo-add(1), cargo-update(1), cargo-build(1), cargo-clean(1)