[Rust Series 2] Install Rust and Run Your First App

한국어 버전

Once you understand the study roadmap from Session 1, it is time to install Rust and see it working. Session 2 covers installing the toolchain with rustup and using cargo to scaffold, build, and run a project. Everything happens on the CLI, so learning the command flow early prevents later friction.

New terms in this post

  1. rustup: The official installer that manages the Rust compiler and related tools.
  2. toolchain: A named bundle like stable, beta, or nightly that ships rustc, cargo, and the standard library together.
  3. Cargo manifest: The Cargo.toml file at the project root that stores the package name, version, and dependencies.

Core ideas

  • Rust installation is a single rustup script and includes the stable toolchain, cargo, and rustc by default.
  • Project creation, build, run, and test flows all go through cargo; cargo new scaffolds the project for you.
  • Once you understand Cargo.toml and src/main.rs, you know exactly where to place code in any tutorial sample.
  • cargo run builds and executes, cargo build only builds, and cargo check compiles quickly without generating a binary.

Code along

1. Install rustup

This walkthrough uses macOS, but Windows and Linux follow nearly the same steps. When in doubt, refer to the official docs for your OS.

On macOS, you can think of two reasonable install paths:

  • Official installer script: the path shown most often in Rust's official docs
  • Homebrew + rustup: convenient if you already use Homebrew heavily

The important part is the same in both cases: let rustup manage the actual Rust toolchain. If you are just getting started, it is cleaner to avoid brew install rust and install only rustup.

If you want to use the official installer, run the script below in Terminal on macOS or Linux (PowerShell works similarly on Windows):

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

If you prefer Homebrew, this path also works:

brew install rustup
rustup default stable

This installs rustup with Homebrew, then lets rustup download and manage rustc and cargo. Unless you have a specific reason, skip brew install rust at the beginning. Mixing both can make PATH order and toolchain ownership harder to reason about.

When asked which toolchain to install, accept the default stable. After the installer finishes, open a new terminal and check versions.

rustc --version
cargo --version

2. Create the first project

Pick a practice folder and run cargo new hello-rust.

cargo new hello-rust
cd hello-rust

You will see a simple structure.

hello-rust/
├── Cargo.toml
└── src/
    └── main.rs

Cargo.toml holds package metadata and dependency info, while src/main.rs contains the starter main function.

3. Build and run

From the project root, run the following commands in order.

cargo build
cargo run
  • cargo build creates a binary inside target/debug.
  • cargo run builds when needed and immediately runs the binary.
  • cargo check skips binary generation and only validates that the code compiles.

Edit the code to feel the build loop.

fn main() {
    let name = "Mathbong";
    println!("안녕하세요, {}!", name);
}

Run cargo run again to see the new output.

4. Quick verification with cargo check

Use cargo check when you only need syntax and type feedback. It skips linking, so it completes faster.

cargo check

Why it matters

  • Many learners get stuck when they paste code before understanding the install and build chain. Session 2 stabilizes the environment so later exercises go faster.
  • Cargo is the standard build system, so a few commands take you from dependency management to testing and release builds.
  • Tools like cargo check shorten the feedback loop while you experiment with ownership and type errors.

Practice in CodeSandbox

The sandbox below uses CodeSandbox's Rust starter. Move the main code into src/main.rs, then compare cargo check and cargo run so you can read the compiler feedback beside the final output.

Live Practice

Rust Practice Sandbox

CodeSandbox

Run the starter project in CodeSandbox, compare it with the lesson code, and keep experimenting.

Rust startercargoterminal
  1. Fork the starter and open src/main.rs
  2. Paste the lesson code and run cargo check plus cargo run in order
  3. Change types, values, or borrowing flow and compare the compiler feedback with the output

Rust practice here is mainly terminal-driven rather than browser-preview driven. Lessons that need multiple files or extra crates may require a bit more setup inside the starter.

Practice

  1. Run rustup show to confirm the active toolchain, then note the output of rustup toolchain list.
  2. Create cargo new playground --vcs none, change the message in main.rs, and run cargo run, capturing the output.
  3. Time cargo check versus cargo build, then summarize when each command makes sense.
  4. Optional: run cargo fmt -- --help to confirm that the formatter is included; we will use it in Session 7.

Wrap-up

You now have a working Rust environment and hands-on experience with cargo new, cargo build, cargo run, and cargo check. Next up: declaring variables with let and mut plus handling scalar, tuple, and array types.

💬 댓글

이 글에 대한 의견을 남겨주세요