Rust Tutorial · Rust Basics · Lesson 2 of 29

Rust Get Started

Install Rust with rustup, create a project with Cargo, and build and run it.

Create a free account to save this page, take notes and track your progress. Sign in

Install

Install Rust with rustup, the official installer and version manager (see rust-lang.org/tools/install), then check:

rustc --version
cargo --version

Cargo

Cargo is Rust's build tool and package manager:

cargo new hello        # creates hello/Cargo.toml and hello/src/main.rs
cd hello
cargo run              # compile and run
cargo build --release  # optimised binary in target/release/
cargo check            # type-check quickly without building
cargo fmt; cargo clippy  # format and lint

src/main.rs starts as:

Example 1
fn main() {
    println!("Hello from my first Cargo project!");
}

Output

Hello from my first Cargo project!

Run this on your computer — see “Get Started” for setup.

Dependencies ("crates") are added with cargo add serde and come from crates.io.

Test yourself

Which command creates a new Rust project?

  1. rustc new
  2. cargo new
  3. rustup init
  4. cargo init-project
Show answer

Answer: cargo new

Was this page helpful?