Error installing a crate via cargo: specified package has no binaries

18,709

cargo install is used to install binary packages that happen to be distributed through crates.io.

If you want to use a crate as a dependency, add it to your Cargo.toml.

Read the Rust getting started guide and the Cargo getting started guide for further information. In short:

cargo new my_project
cd my_project
echo 'curl = "0.3.0"' >> Cargo.toml

Amusingly, you can install a third-party Cargo subcommand called cargo-edit using cargo install that makes it easier to modify your Cargo.toml file to add dependencies!

cargo install cargo-edit
cargo add curl

An important thing to note is that every Cargo project manages and compiles a separate set of dependencies (some background info). Thus it doesn't make sense to install a compiled library. The source code for each version of a library will be cached locally, avoiding downloading it multiple times.

See also:

Share:
18,709

Related videos on Youtube

q9f
Author by

q9f

Libre software and disrupting technologies.

Updated on June 15, 2022

Comments

  • q9f
    q9f almost 2 years

    I'm trying to install a Rust crate on my system (Arch Linux) using Cargo. I can search for crates and find what I need, for example:

     $ cargo search curl | head -n3
        Updating registry `https://github.com/rust-lang/crates.io-index`
    curl (0.3.0)             Rust bindings to libcurl for making HTTP requests
    curl-sys (0.2.0)         Native bindings to the libcurl library
    

    When I try to install it, I get the following error:

     $ cargo install curl
        Updating registry `https://github.com/rust-lang/crates.io-index`
    error: specified package has no binaries
    

    What does this mean? Do I have to build it from source first? What's the point of Cargo if it does not install it in the first place?

     $ uname -a
    Linux 4.6.1-2-ARCH #1 SMP PREEMPT Thu Jun 2 15:46:17 CEST 2016 x86_64 GNU/Linux
     $ rustc --version
    rustc 1.9.0
     $ cargo --version
    cargo 0.10.0 (10ddd7d 2016-04-08)
    
  • user5359531
    user5359531 almost 5 years
    Seems like this does not actually fix the problem. The library is already listed as a dependency under Cargo.toml. When I try to build the project, it fails because the dependency is not installed. When I try to install the dependency, it fails due to the error in the original post.
  • Roger Dahl
    Roger Dahl over 3 years
    @user5359531 - Try cargo run.