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.
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:
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?
rustc newcargo newrustup initcargo init-project
Show answer
Answer: cargo new