How to use `cargo install` to install mutiple crates with specific versions?

Currently, we can install multiple crates in one line, for example:

$ cargo install foo bar

However, if we want to choose specific version for each crate, we have to split into multiple lines:

$ cargo install --version x.x.x foo
$ cargo install --version y.y.y bar

I am looking for a feature like ruby gems:

$ gem install rails:0.14.4 rubyzip:'< 1'

Unfortunately, cargo install -h does not show any useful information. I am wondering if cargo supports this feature.

Are you sure you need cargo install?

cargo install is specifically for installing binaries, not arbitrary crates, and from the way you framed the question it seems like you want the latter. Apologies if I got that wrong!

If you want to add a library as a dependency, you do this via Cargo.toml’s, [dependenceis] section:

[dependencies]
foo = "x.x.x"

To answer the original question, to my knowledge, it is not possible to specify multiple crates with --version for cargo install.

Are you sure you need cargo install?

Yes, I am sure. I am building a Docker image which should not upgrade executable dependencies while building. To set a specific version for each dependency in Dockerfile is a good practice.

To answer the original question, to my knowledge, it is not possible to specify multiple crates with --version for cargo install.

That’s unfortunate :cry: