To start a new package with Cargo, use cargo new: $ cargo new hello_world Cargo defaults to --bin to make a binary program. To make a library, we would pass --lib, instead. Let’s check out what Cargo has generated for us: $ cd hello_world $ tree . . ├── Cargo.toml └── src └── main.rs 1 directory, 2 files
cargo-metadata(1) NAME. cargo-metadata — Machine-readable metadata about the current package. SYNOPSIS. cargo metadata [options]. DESCRIPTION. Output JSON to stdout containing information about the workspace members and resolved dependencies of the current package.
As of Rust 1.41.0, you can use the following command to update crates to their latest version:
cargo install <crate>
This came from pull request #6798 (Add install-upgrade) and was stabilized in #7560 (Stabilize install-upgrade).
Instead of failing when detects a package is already installed, it will upgrade if the versions don't match, or do nothing (exit 0) if it is considered "up-to-date".cargo install
The following command will always uninstall, download and compile the latest version of the crate - even if there's no newer version available. Under normal circumstances the feature should be preferred as it does save time and bandwidth if there's no new version of the crate.install-upgrade
cargo install --force <crate>
Further information can be found in the GitHub issue rust-lang/cargo#6797 and in the official documentation chapter.
The command line
cargo help install
produces detailed help information. Among others it lists common EXAMPLES, e.g.
View the list of installed packages:
cargo install --list