LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 313 min read

Installing Rust & Cargo

Install Rust with rustup, understand the difference between rustc and Cargo, and create and run your first Cargo project.

Introduction

Before writing any real Rust code, you need the Rust toolchain installed. Rust's tooling story is unusually smooth compared to many languages — a single installer gives you the compiler, package manager, and standard library together.

This lesson walks through installing Rust with rustup, verifying the install, creating your first project with Cargo, and the handful of Cargo commands you'll reach for constantly.

What You Will Learn
  • The difference between rustup, rustc, and Cargo.
  • How to install Rust on your machine.
  • How to verify your installation and check versions.
  • How to create, build, and run your first Cargo project.
  • The most important Cargo commands for everyday development.

rustup, rustc, and Cargo

Rust's tooling is made up of three pieces that work together. `rustup` is the toolchain installer and version manager — it installs and updates everything else, and lets you switch between stable, beta, and nightly Rust. `rustc` is the actual compiler that turns Rust source code into machine code. `cargo` is the build tool and package manager that calls `rustc` for you, manages dependencies, runs tests, and generates documentation.

In day-to-day development, you will use `cargo` almost exclusively — it is rare to invoke `rustc` directly once a project exists.

Installing Rust

On macOS, Linux, or another Unix-like system, open a terminal and run the official rustup install script:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

On Windows, download and run `rustup-init.exe` from rust-lang.org, which walks you through the same installation interactively. Either way, once installation finishes, restart your terminal (or open a new one) so the `cargo` and `rustc` commands are available on your PATH.

Verifying Your Installation

Confirm everything installed correctly by checking both tool versions:

rustc --version
cargo --version
Example Output

Click Run to see what this code prints.

Your exact version numbers will differ depending on when you install — that's expected. What matters is that both commands print a version instead of a "command not found" error.

Creating Your First Project

Cargo can scaffold an entire project for you — a `Cargo.toml` manifest file plus a `src/main.rs` with a working "Hello, world!" already in it.

cargo new hello_rust
cd hello_rust
cargo run
Example Output

Click Run to see what this code prints.

`cargo new` created a `Cargo.toml` (your project's manifest, listing its name, version, and dependencies) and a `src/main.rs` (your program's entry point). `cargo run` compiled it and ran the resulting binary in one step.

Cargo Commands You'll Use Constantly

CommandWhat It Does
cargo new <name>Creates a new binary project with a Cargo.toml and src/main.rs.
cargo buildCompiles the project (debug build by default) into target/debug/.
cargo runCompiles (if needed) and runs the resulting binary in one step.
cargo checkType-checks the project without producing a binary — much faster for quick feedback.
cargo build --releaseCompiles with optimizations enabled into target/release/.
cargo testRuns all tests in the project.
cargo doc --openBuilds and opens the project's documentation in a browser.

Editor Setup

Install the `rust-analyzer` extension for your editor (available for VS Code, Neovim, and others). It gives real-time type information, inline error checking, autocompletion, and go-to-definition — it makes an enormous difference in how comfortable learning Rust feels.

Common Mistakes

Avoid These Mistakes
  • Forgetting to restart your terminal after installation, so `cargo` and `rustc` aren't found on the PATH yet.
  • Editing `Cargo.lock` by hand — it is generated and managed by Cargo; edit `Cargo.toml` instead.
  • Running the slower `cargo build` repeatedly while just checking for typos, instead of the much faster `cargo check`.
  • Skipping `rust-analyzer` setup and trying to learn Rust's type system without any inline feedback from your editor.

Best Practices

  • Install Rust via `rustup` rather than an OS package manager — it makes updating and switching toolchain versions much easier.
  • Run `cargo check` constantly while writing code, and save `cargo build`/`cargo run` for when you actually need to execute something.
  • Commit `Cargo.lock` for binary applications so builds stay reproducible; library crates typically omit it so consumers resolve their own compatible versions.
  • Run `rustup update` periodically to stay on a current stable release and pick up compiler improvements.

Frequently Asked Questions

rustc is the compiler itself; cargo is the build system and package manager that invokes rustc for you and manages dependencies, tests, and documentation.

No — rustup installs rustc, cargo, and the standard library together as a single toolchain.

The official public registry for Rust packages ("crates") that Cargo downloads dependencies from automatically.

Run `rustup update` to update your installed toolchains to the latest stable release.

Key Takeaways

  • rustup installs and manages your Rust toolchain; rustc is the compiler; cargo is the build tool and package manager you'll use daily.
  • `cargo new` scaffolds a new project with a Cargo.toml and src/main.rs.
  • `cargo run` builds and runs your project in one command; `cargo check` gives fast feedback without producing a binary.
  • Installing the rust-analyzer editor extension is one of the highest-value setup steps for learning Rust.

Summary

You now have Rust and Cargo installed, understand what each tool in the toolchain does, and have created, built, and run your first project. Next, you'll dig into variables, constants, and Rust's data types.

Next Lesson →

Variables & Data Types