Why No "Cargo Install" For Libraries?

I am coming from the world of node.js and npm where you can easily run "npm install blah" in an existing project to install the blah library. The cli tool figures out the latest version that will work, installs it, and automatically updates the package.json file.

When I just tried to run "cargo install dialogue" in a rust project I was kind of disappointed that cargo gave me this error:

error: there is nothing to install in `dialoguer v0.10.0`, because it has no binaries
`cargo install` is only for installing programs, and can't be used with libraries.
To use a library crate, add it as a dependency in a Cargo project instead.

Is there a reason why cargo purposely makes the user update cargo.toml by hand? Is there any flag or other command I can use to install a library easily similar to the npm way? Thanks!

There is a cargo sub-command for it called cargo edit. You can install it with cargo install cargo-edit. Then you can add packages like cargo add regex@0.1.41.


cargo install is specifically for installing executables into your system (ie. somewhere along $PATH) so they can be run from the command line. It is not for adding dependencies to your projects.


And the cargo add command is going to be integrated into Cargo so it will always be available:



That's fantastic news!

In Cargo, install means a different thing. It's closer to npm i -g and only for the .bin dir.

To "install" dependencies in a project, edit Cargo.toml files.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.