← Back to Rust series
🦀
Basics
Basics · Prerequisite: none

01. Getting Started with Rust (rustup · cargo · hello world)

Rust is a systems programming language that guarantees memory safety at compile time. Without a garbage collector it delivers C/C++ class performance while preventing data races, null-pointer bugs, and use-after-free at the type-check phase. In this lesson you install the toolchain with rustup and run your first project with cargo.

RustrustupcargobasicsHello Worldgetting started
Duration
~1-1.5 hours
Level
📊 Beginner
Prerequisite
🎯 None
OUTCOME
Rust is a systems programming language that guarantees memory safety at compile time. Without a garbage collector it delivers C/C++ class performance while preventing data races, null-pointer bugs, and use-after-free at the type-check phase. In this lesson you install the toolchain with rustup and run your first project with cargo.

What you'll learn

  • 1Install the stable Rust toolchain with rustup
  • 2Verify rustc and cargo versions and understand the split
  • 3Create your first project with `cargo new`
  • 4Understand the difference between `cargo run` / `cargo build` / `cargo check`
  • 5Read the basic structure of `Cargo.toml`

Overview

Rust started at Mozilla in 2010 and spread quickly through Firefox, AWS, Discord, and even the Linux kernel. The core promise is simple — **the compiler guarantees memory safety**. With no garbage collector, problems like dangling pointers or data races are caught at build time, so you stop spending Friday nights debugging mysterious crashes.

This is lesson 1 of a 22-part track. Install → first build → on to variables (lesson 2) without missing a beat.

Core Concepts

1) rustup — Rust's official toolchain manager

Rust isn't installed system-wide like Python. **rustup** manages stable / beta / nightly channels side by side and lets you switch instantly.

  • **stable** — shipped every 6 weeks, the production channel
  • **beta** — release candidate for the next stable
  • **nightly** — built daily, opt-in experimental features

2) cargo — build / package / test in one tool

Equivalent to Node's npm or Python's pip — except cargo bundles **build system + dependency management + test runner + doc generator** behind one command.

CommandRole
cargo newCreate a new project
cargo buildDebug build (target/debug/)
cargo build --releaseRelease build with optimizations
cargo runBuild and run
cargo checkType-check only, no binary (fast)
cargo testRun tests

3) Relation to rustc

**rustc** is the actual compiler. cargo calls rustc under the hood. You'll invoke rustc directly only for one-file experiments — day to day it's all cargo.

Hands-on Examples

rustup install is a one-liner. macOS / Linux:

bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Windows: grab rustup-init.exe from https://rustup.rs

Open a fresh shell and check versions:

bash
rustc --version
# rustc 1.7x.x (yyyymmdd)

cargo --version
# cargo 1.7x.x (yyyymmdd)

Create and run your first project:

bash
cargo new hello_rust
cd hello_rust
cargo run
#    Compiling hello_rust v0.1.0
#     Finished `dev` profile [unoptimized + debuginfo] target(s)
#      Running `target/debug/hello_rust`
# Hello, world!

What got generated in `src/main.rs` and `Cargo.toml`:

rust
// src/main.rs
fn main() {
    println!("Hello, world!");
}
toml
# Cargo.toml
[package]
name = "hello_rust"
version = "0.1.0"
edition = "2021"

[dependencies]

Common Mistakes

Q. cargo: command not found, what's wrong?

A. After rustup installs you need to **open a new shell** so PATH picks up. Or run `source $HOME/.cargo/env` to refresh the current shell.

Q. Where does cargo build put the binary?

A. `target/debug/<project>` (with `.exe` on Windows). Release builds go in `target/release/`. For a quick test `cargo run` is more convenient.

Q. The `!` in `println!` — isn't that a function call?

A. The `!` marks a **macro**, not a function. Macros generate code at compile time, enabling things like variadic arguments and compile-time format-string checks. `format!`, `vec!`, `assert_eq!` are all macros too.

Recap

  • rustup manages the Rust toolchain
  • cargo unifies build / run / test / docs
  • First project: `cargo new`, run with `cargo run`
  • Use `cargo check` for fast iteration, `cargo build --release` for release
  • `println!` is a macro, not a function

Try It Yourself

  1. Create `coding_now_rust_01` with `cargo new` and run it with `cargo run`
  2. Change the message in main.rs to include your own name and run again
  3. Run `cargo build --release` and compare the binary size in `target/release/` to the debug build
Example code / lecture materials

All lecture materials and example code are openly available on GitHub.

View on GitHub ↗