Rust Get Started
Let’s get Rust running on your machine and build your first program. If you’d rather not install anything yet, you can follow along in the Rust Playground and come back to this page later.
Step 1: Install Rust with rustup
Section titled “Step 1: Install Rust with rustup”The official way to install Rust is a tool called rustup. It installs the Rust compiler, the cargo build tool, and keeps everything up to date.
Go to rustup.rs and follow the instructions for your system:
-
Windows — download and run
rustup-init.exe, then accept the default options. -
macOS / Linux — paste this into your terminal:
Terminal window curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Step 2: Check it worked
Section titled “Step 2: Check it worked”Close and reopen your terminal, then run:
rustc --versioncargo --versionYou should see version numbers like rustc 1.xx.0. If you do, you’re ready to go.
rustcis the Rust compiler (it turns your code into a program).cargois Rust’s all-in-one tool for building, running, testing, and managing projects. You’ll usecargofor almost everything.
Step 3: Create your first project
Section titled “Step 3: Create your first project”Instead of creating files by hand, let cargo set up a project for you:
cargo new hello_rustcd hello_rustThis creates a folder called hello_rust with everything a Rust project needs:
hello_rust/├── Cargo.toml # project settings and dependencies└── src/ └── main.rs # your code goes hereCargo.tomldescribes your project (its name, version, and any libraries it uses).src/main.rsis the starting file —cargoeven fills it with a Hello World for you.
Step 4: Run it
Section titled “Step 4: Run it”From inside the project folder, run:
cargo runYou’ll see cargo compile the project and then print:
Hello, world!That’s it — you just built and ran a Rust program.
Understanding the code
Section titled “Understanding the code”Open src/main.rs and you’ll find:
fn main() { println!("Hello, world!");}fn main() { ... }defines the main function — every Rust program starts running here.println!("...")prints a line of text to the screen.
Try changing the message and running cargo run again:
fn main() { println!("Hello from my first Rust program!");}cargo run vs cargo build
Section titled “cargo run vs cargo build”Two commands you’ll use constantly:
| Command | What it does |
|---|---|
cargo run |
Compiles and runs your program (best while developing) |
cargo build |
Just compiles it — the program lands in target/debug/ |
cargo build --release |
Compiles an optimized, faster version for shipping |
Step 5: Set up your editor (recommended)
Section titled “Step 5: Set up your editor (recommended)”For the best experience, install the rust-analyzer extension in your editor. It gives you autocompletion, inline error messages, and type hints as you type.
- VS Code — install the rust-analyzer extension
- Most other editors (JetBrains, Neovim, etc.) support rust-analyzer too.
- Install Rust with
rustupfrom rustup.rs. - Verify with
rustc --versionandcargo --version. - Create a project with
cargo new, run it withcargo run. - A project has a
Cargo.toml(settings) andsrc/main.rs(your code). - Install rust-analyzer in your editor for a much smoother ride.
Quick check
Section titled “Quick check”Quick check
1. What tool installs the Rust compiler, cargo, and keeps them updated?
2. Which file describes a Rust project's name, version, and dependencies?
3. Which command only compiles your program without running it?
Score: 0 / 3