Skip to main content
Rust Programming
CHAPTER 02 Beginner

Installing Rust and Setting Up Environment

Updated: May 18, 2026
5 min read

# CHAPTER 2

Installing Rust and Setting Up Environment

1. Chapter Introduction

To write and run Rust code, you need the right tools installed on your computer. Unlike older languages where you have to manually configure compilers, linkers, and build systems, Rust provides a unified, modern toolchain. In this chapter, we will install rustup (the Rust installer), learn about Cargo (the build system and package manager), and configure a code editor like Visual Studio Code.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Install Rust using rustup on Windows, macOS, or Linux.
  • Verify the installation of rustc and cargo.
  • Understand the role of Cargo in Rust projects.
  • Set up Visual Studio Code with the rust-analyzer extension.
  • Update and uninstall Rust.

3. Installing Rust with rustup

The official and recommended way to install Rust is via rustup, a command-line tool for managing Rust versions.

For Linux and macOS: Open your terminal and paste the following command:

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

Follow the on-screen prompts (usually just pressing 1 for the default installation).

For Windows:

  1. 1. Go to the official Rust website: https://rustup.rs/
  1. 2. Download and run rustup-init.exe.
  1. 3. *Note:* Rust on Windows requires the C++ build tools. If you don't have them, the installer will prompt you to install the Visual Studio C++ Build Tools.

4. Verifying the Installation

Once installed, restart your terminal or command prompt and type the following to verify:
bash
12345
# Check the Rust compiler version
rustc --version

# Check the Cargo package manager version
cargo --version

If you see version numbers (e.g., rustc 1.70.0), congratulations! Rust is successfully installed.

5. Understanding the Toolchain

When you install Rust via rustup, you get three main tools:
  1. 1. rustup: The updater and version manager. (Use rustup update to get the latest version of Rust).
  1. 2. rustc: The actual Rust compiler. It turns your .rs code files into executable binary files. (You will rarely use this directly).
  1. 3. cargo: The Rust package manager and build system. You will use Cargo for *everything*. It builds your project, downloads dependencies, runs tests, and generates documentation.

6. Setting Up the IDE (VS Code)

Writing Rust in Notepad is a bad idea. Rust relies heavily on real-time compiler feedback to help you fix memory errors.

Recommended Setup:

  1. 1. Download and install Visual Studio Code (VS Code).
  1. 2. Open VS Code and go to the Extensions panel (Ctrl+Shift+X).
  1. 3. Search for and install rust-analyzer.
*Note:* Do not install the older extension named "Rust". rust-analyzer is the official, vastly superior language server.
  1. 4. (Optional) Install the CodeLLDB extension for debugging support.

7. Creating Your First Project with Cargo

Let's see how easy it is to create a project.
bash
12345678
# Tell cargo to create a new project folder named "hello_rust"
cargo new hello_rust

# Move into the new directory
cd hello_rust

# Run the project!
cargo run

When you run cargo run, Cargo automatically compiles the code and executes it, printing Hello, world! to the terminal.

8. Anatomy of a Cargo Project

If you look inside the hellorust folder, you will see:
  • Cargo.toml: The configuration file for your project (stores your project name, version, and external libraries/dependencies).
  • src/: A folder containing your source code.
  • src/main.rs: The entry point of your application.

9. Common Mistakes

  • Using rustc directly for large projects: Beginners often try to compile files using rustc main.rs. While this works for a single file, it breaks down when you have multiple files and dependencies. Always use cargo build or cargo run.
  • Ignoring the C++ Build Tools prompt on Windows: If you skip installing the Visual Studio C++ build tools on Windows, the Rust compiler will fail to link your executable and throw a cryptic error.

10. Best Practices

  • Keep Rust Updated: The Rust team releases a new version every 6 weeks. Run rustup update occasionally to get the latest features and performance improvements.
  • Use rustfmt: Rust comes with a built-in code formatter. You can format your entire project by running cargo fmt.

11. Exercises

  1. 1. Install Rust using rustup on your machine.
  1. 2. Open your terminal, create a new project called myfirst_app using Cargo.
  1. 3. Open the project in VS Code, ensure rust-analyzer activates, and run it using cargo run.

12. MCQs with Answers

Question 1

What is the recommended tool to install and manage Rust versions?

Question 2

What is the name of Rust's compiler?

Question 3

What is Cargo?

Question 4

Which VS Code extension is officially recommended for Rust development?

Question 5

What command creates a new Rust project using Cargo?

Question 6

What command both compiles and executes a Cargo project?

Question 7

What file manages your project's dependencies and metadata?

Question 8

What command updates Rust to the latest version?

Question 9

In which folder does Cargo place your actual source code files?

Question 10

Windows users must install what prerequisite to compile Rust successfully?

13. Interview Questions

  • Q: Explain the difference between rustc and cargo. Which one should you use daily and why?
  • Q: What is the purpose of the Cargo.toml file?
  • Q: How does rustup benefit a developer working on multiple projects with different Rust versions?

14. FAQs

  • Do I have to use VS Code? No, you can use IntelliJ IDEA (with the Rust plugin), CLion, or even Vim/Neovim. rust-analyzer works with almost all modern editors.
  • Where are compiled files stored? When you run cargo build, Cargo creates a target/debug/ folder and places your compiled .exe (or binary) there.

15. Summary

Setting up Rust is a streamlined experience thanks to rustup and Cargo. Cargo acts as your all-in-one assistant, handling project creation, compilation, and dependency management. With rust-analyzer running in your code editor, you are now fully equipped to write modern systems code.

16. Next Chapter Recommendation

Your environment is ready! In Chapter 3: Rust Syntax and First Program, we will break down the main.rs file line by line, write our first custom program, and learn the basic syntax rules of Rust.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·