This tutorials explains frequently used commands of Cargo Package Manager

  • cargo init
  • cargo build
  • cargo test
  • cargo publish
  • cargo run
  • cargo doc

How to create a new Rust project

cargo new command used to create a new application.

cargo new rustapp
 Created binary (application) `rustapp` package

It creates a new application rustapp folder, It contains cargo.toml to store metadata such as name, version, dependencies sections and profiles

You can also use cargo new --vcs none to create a new project without any version control system.

How to install crate binaries from

cargo install command used to install binaries from

cargo install package

package is an crate name library from

Cargo Release profiles

release profiles are profiles to store the precreated and custom configuration with more configuration to compile code in Rust. It used with cargo build command

Cargo has two profiles release and dev.

release profile is used to release packages dev is a default profile used for development

cargo build uses default profile dev

To build a release profile, use –release option

cargo build
cargo build --release

Publish a package

First Login to website and get token

cargo login token

Next, run cargo publish command to publish to

cargo publish