Welcome to your first lesson in the "Rust for CLI and WASM" course. Given your extensive background in front-end development, you're likely familiar with the importance of a solid toolchain for productivity. This lesson is designed to get you up and running with Rust's powerful and integrated development environment, setting the stage for the more advanced topics we'll tackle later.
Today, we will focus on installing the Rust toolchain and mastering its central command-line tool, Cargo. By the end of this lesson, you will be able to set up your development environment and perform all the essential project operations: creating, building, running, testing, formatting, and linting a Rust application. This foundational knowledge is crucial, as Cargo will be your constant companion throughout your Rust journey, much like npm or yarn is in the JavaScript ecosystem.
1. Setting Up the Rust Toolchain with rustup
The first step is to install the Rust compiler and its associated tooling. The official and recommended way to do this is with rustup, the Rust toolchain installer. Think of rustup as being similar to nvm (Node Version Manager); it allows you to install and manage multiple versions of the Rust toolchain (stable, beta, and nightly) seamlessly.
The following article provides a clear, step-by-step guide to the installation process.
How to Install and Configure Rust Toolchain on Ubuntu
This guide from OneUptime covers the installation and configuration of the Rust toolchain. We'll focus on the installation process and the management of components.
In the section "Installing Rust with rustup," follow the instructions to install the toolchain. When prompted, choosing the default installation (option 1) is sufficient. After the installation, run the source $HOME/.cargo/env command as instructed to update your shell's PATH, and verify that rustc, cargo, and rustup are correctly installed. Next, in the "Installing Components" section, learn how to install the rustfmt and clippy components. These are the official code formatter and linter, respectively, and are indispensable for writing idiomatic Rust.
The rustup installer downloads several key tools:
rustc: The Rust compiler.cargo: Rust's build system and package manager.rustup: The toolchain manager itself.
For a visual walkthrough and a bit more context on what each part of the toolchain does, the following video is helpful.
Install the Rust Toolchain on an Ubuntu Linux Server 🦀
This video by Trevor Sullivan demonstrates the installation process on a Linux server and explains the core components of the Rust toolchain.
Watch from the start to see the rustup.rs website and the installation command. The segment from explains the roles of rustc, cargo, rustfmt, and clippy, which will give you a good mental model of the ecosystem. You can watch the interactive installation walkthrough from this section if you want to see the customization options, though the defaults are fine for now.
With the toolchain installed, you're ready to explore its most important component: Cargo.
2. Project Management with Cargo
Cargo is the heart of the Rust development workflow. It unifies functionality that often requires multiple tools in other ecosystems. It's a package manager (like npm/yarn), a build tool (like Webpack/Vite), a test runner, and more, all in one.
Creating Your First Project
Let's start by creating a new "Hello, World!" project with Cargo.
cargo new hello_rust
cd hello_rust
This command creates a new directory called hello_rust with the following structure:
Cargo.toml: The manifest file, analogous topackage.json. It contains metadata, dependencies, and build configurations for your project.src/main.rs: The source code file for your application's entry point..gitignore: A pre-configured file for Git.
The cargo new command creates a binary project by default, which is an executable program. To create a library (a package of code meant to be used by other programs), you would use cargo new my_library --lib.
The Core Development Workflow
Now, let's explore the essential Cargo commands that you will use daily. The following article provides an excellent, command-oriented overview.
How to Use Cargo for Rust Project Management
This article is a comprehensive guide to Cargo's features. We'll focus on the commands for building, running, testing, and ensuring code quality.
Please read the following sections to understand the core commands: Building and Running Projects: Read this section to understand cargo build and cargo run. Pay attention to the distinction between a default debug build and an optimized release build (--release). Testing with Cargo: Skim this section to see how to run tests. Rust's built-in testing capabilities are a major strength. Useful Cargo Commands: This is a critical section. Focus on: The "Code Quality" subsection to learn about cargo fmt and cargo clippy. The "Checking Code" subsection to understand cargo check, a command you'll use constantly for quick feedback.
Let's summarize and contextualize those commands:
cargo run: This command compiles and runs your binary. During development, it creates an unoptimized debug build in thetarget/debug/directory. For production, you'll usecargo run --release, which creates a highly optimized binary intarget/release/.cargo check: This is one of the most useful commands. It quickly checks your code for compilation errors without producing an executable. Since it skips the final code generation step, it's significantly faster than a fullcargo build, making it ideal for frequent checks as you code.cargo test: Executes any tests in your project. Cargo automatically finds and runs functions annotated with#[test].cargo fmt: This command auto-formats your code according to the official Rust style guidelines. It's the "Prettier" of the Rust world and helps ensure consistency across projects.cargo clippy: This is a powerful linter that goes far beyond simple style checks. It catches common mistakes and, more importantly, suggests more idiomatic and performant ways to write your Rust code. Think of it as a very opinionated ESLint that acts as a mentor.
3. A Typical Development Loop
A modern Rust workflow integrates these tools to provide a tight feedback loop. While we will cover CI/CD in a later module, the local workflow typically looks like this:
- Write Code: You make changes to your
.rsfiles. - Check: You frequently run
cargo checkto get near-instant feedback on compiler errors. - Lint & Format: Before committing, you run
cargo clippyto catch logical errors andcargo fmtto clean up formatting. - Test: You run
cargo testto ensure your logic is correct. - Run: You use
cargo runto test the application manually.
This entire process is often automated. The diagram below shows how these commands fit into a professional workflow, including integration with tools like GitHub Copilot and GitHub Actions for continuous integration.

Notice how the Format, Lint, and Test steps appear both locally and in the automated GitHub Actions flow. This is a common practice to ensure code quality before it's merged.
Conclusion
In this lesson, you have successfully set up your Rust development environment and learned the fundamental workflow for managing projects with Cargo. These tools provide a robust and efficient foundation for everything we will build in this course.
Key Takeaways:
rustupis the tool for installing and managing Rust toolchains.cargois your all-in-one build tool, package manager, and test runner.- The essential daily commands are
cargo check,cargo run,cargo test,cargo fmt, andcargo clippy. - Rust development emphasizes a tight feedback loop, with tools designed for rapid, incremental checks.
Now that your environment is ready, our next lesson will dive into the Rust language itself. We will start with the fundamentals: declaring variables, defining functions, and using control flow constructs. You'll finally get to put these powerful tools to use writing some code.