Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does cargo have an equivalent npm install --save option to automatically add dependencies to Cargo.toml? [duplicate]

I expected there to be something like cargo install stopwatch but could not find it in the docs.

I've been finding the package version and manually adding it to Cargo.toml:

[dependencies]
stopwatch = "0.0.6"

But this is tedious and I feel it should be more automated.

like image 955
Johan Larsson Avatar asked Jan 26 '26 15:01

Johan Larsson


1 Answers

As of Rust 1.62.0, there is a built-in add sub-command to add dependencies and avoid having to edit the Cargo.toml file yourself.

To add the latest version:

cargo add stopwatch

To add a specific version:

cargo add [email protected]

More details in the Cargo book.

like image 87
Nerpson Avatar answered Jan 29 '26 11:01

Nerpson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!