Skip to content

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.

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

Close and reopen your terminal, then run:

Terminal window
rustc --version
cargo --version

You should see version numbers like rustc 1.xx.0. If you do, you’re ready to go.

  • rustc is the Rust compiler (it turns your code into a program).
  • cargo is Rust’s all-in-one tool for building, running, testing, and managing projects. You’ll use cargo for almost everything.

Instead of creating files by hand, let cargo set up a project for you:

Terminal window
cargo new hello_rust
cd hello_rust

This 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 here
  • Cargo.toml describes your project (its name, version, and any libraries it uses).
  • src/main.rs is the starting file — cargo even fills it with a Hello World for you.

From inside the project folder, run:

Terminal window
cargo run

You’ll see cargo compile the project and then print:

Hello, world!

That’s it — you just built and ran a Rust program.

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!");
}
▶ Try it Yourself

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

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 rustup from rustup.rs.
  • Verify with rustc --version and cargo --version.
  • Create a project with cargo new, run it with cargo run.
  • A project has a Cargo.toml (settings) and src/main.rs (your code).
  • Install rust-analyzer in your editor for a much smoother ride.