Crash Courses · Basic
Environment & Hello World
Install Rust via rustup, configure VS Code, and run your first program
20 min read+155 XP on completionCert: Rust Crash Course
Tap any word in the text below to start reading from there.
Setting Up Rust
1. Install via rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shOn Windows, download and run rustup-init.exe from https://rustup.rs.
After installation:
rustc --version # rustc 1.78.0 (9b00956e5 2024-04-29)
cargo --version # cargo 1.78.0 (54d8815d0 2024-03-26)2. VS Code Setup
Install the rust-analyzer extension (extension id: rust-lang.rust-analyzer). This is the official extension — do not install the old "Rust" extension.
rust-analyzer provides:
- Real-time type inference
- Inline diagnostics from the borrow checker
- Code actions and refactors
- Go-to-definition across crates
3. Create a Project
cargo new hello_rust
cd hello_rustThis creates:
hello_rust/
Cargo.toml
src/
main.rs4. Your First Program
src/main.rs already contains Hello World:
fn main() {
println!("Hello, World!");
}Run it:
cargo run
# Compiling hello_rust v0.1.0
# Finished dev profile
# Running target/debug/hello_rust
# Hello, World!Build a release binary (optimized):
cargo build --release
./target/release/hello_rust5. println! is a Macro
The ! suffix means println! is a macro, not a function. Rust macros operate at compile time and can be variadic — that is why println!("{} {}", a, b) works without generic function overloads.
6. Cargo.toml
[package]
name = "hello_rust"
version = "0.1.0"
edition = "2021"
[dependencies]The edition field picks which Rust edition to use. Always use 2021 for new projects.
7. Useful Cargo Commands
cargo check # fast type-check without producing a binary
cargo clippy # linter — much stricter than the compiler
cargo fmt # auto-format all Rust files
cargo test # run all tests
cargo doc --open # build and open docsReading progress
0% read
In this module
rustup
cargo
rustc
Crate
0%