Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting Started

What you’ll learn: How to install Rust, create the first project, and map the Cargo workflow to what Java developers know from Maven or Gradle.

Difficulty: 🟢 Beginner

Install the Toolchain

Use rustup to install Rust and manage toolchains:

winget install Rustlang.Rustup
rustup default stable
rustc --version
cargo --version

The Java analogy is a mix of JDK installer plus SDK manager, except Rust keeps the toolchain story much tighter.

Create the First Project

cargo new hello-rust
cd hello-rust
cargo run

That single command sequence creates the project, compiles it, and runs it.

Cargo vs Maven / Gradle

TaskJava habitRust habit
initialize projectgradle init or archetypecargo new
compilemvn package or gradle buildcargo build
run testsmvn test or gradle testcargo test
run appplugin taskcargo run
add dependencyedit build filecargo add crate_name

First Program

fn main() {
    println!("Hello, Rust!");
}

There is no class wrapper, no public static void main, and no object ceremony around the entry point.

Reading Arguments

fn main() {
    let args: Vec<String> = std::env::args().collect();
    println!("{args:?}");
}

For anything beyond trivial parsing, use clap.

The Three Commands to Memorize

cargo check
cargo test
cargo run

cargo check is especially valuable for new Rust developers because it gives fast feedback without producing a final binary.

Advice

  • Install rust-analyzer in the editor immediately.
  • Prefer cargo check during rapid iteration.
  • Keep the first project small; ownership is easier to learn on tiny programs.

Once Cargo and the compiler stop feeling foreign, the rest of Rust becomes much easier to approach.