Rust Setting Up the Development Environment

Before you write any Rust code, you need to install the right tools on your computer. The setup takes about five minutes and works the same way on Windows, macOS, and Linux.

The Three Tools You Need

  • rustup — The installer that manages Rust versions on your machine
  • rustc — The Rust compiler that turns your code into a program
  • cargo — The build tool and package manager that organizes your projects

The Toolbox Diagram

[ rustup ]  =  The toolbox itself — installs and updates tools
[ rustc  ]  =  The hammer — compiles your code
[ cargo  ]  =  The workbench — manages your whole project

When you install rustup, it automatically installs rustc and cargo for you. You only need one command to get started.

Step 1: Install rustup

On macOS and Linux

Open your terminal and run this command:

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

The installer will ask you a question. Press Enter to choose the default installation. Wait for it to finish, then close and reopen your terminal.

On Windows

Go to https://rustup.rs in your browser. Download the file named rustup-init.exe and run it. Follow the on-screen steps. When it finishes, open a new Command Prompt or PowerShell window.

Step 2: Check the Installation

After installation, confirm that everything works by running these commands one at a time:

rustc --version
cargo --version

You will see output like this:

rustc 1.78.0 (9b00956e5 2024-04-29)
cargo 1.78.0 (54d8815d0 2024-04-09)

The version numbers on your screen may differ, but any version number means the installation worked.

Step 3: Choose a Code Editor

You can write Rust code in any text editor, but some editors give you extra help like code completion, error highlighting, and automatic formatting.

Recommended: Visual Studio Code

Visual Studio Code (VS Code) is free and works on all operating systems. After installing VS Code, open it and install the extension named rust-analyzer. This extension understands Rust code and shows errors as you type.

Other Options

  • IntelliJ IDEA with the Rust plugin — good for developers already using JetBrains tools
  • Neovim with rust-analyzer — good for developers who prefer a terminal editor
  • Sublime Text with Rust Enhanced plugin

Understanding Cargo: Your Project Manager

Cargo does several jobs for you automatically. Most developers use Cargo for every Rust project instead of calling rustc directly.

What Cargo Does

[ cargo new  ]  Creates a new project with the right folder structure
[ cargo build]  Compiles your code into a program
[ cargo run  ]  Compiles and runs your program in one step
[ cargo test ]  Runs all your tests
[ cargo check]  Checks for errors without building the full program (faster)

Create Your First Cargo Project

Run this command in your terminal to create a new project called hello_rust:

cargo new hello_rust

Cargo creates a folder with this structure:

hello_rust/
├── Cargo.toml       ← Project settings and dependencies
└── src/
    └── main.rs      ← Your Rust source code lives here

The House Diagram

hello_rust/          ← The house (project folder)
│
├── Cargo.toml       ← The blueprint (project name, version, libraries you use)
│
└── src/             ← The rooms (source code)
    └── main.rs      ← The main room (program starts here)

The Cargo.toml File

Open Cargo.toml and you will see something like this:

[package]
name = "hello_rust"
version = "0.1.0"
edition = "2021"

[dependencies]

The [package] section holds information about your project. The [dependencies] section is where you list external libraries your project needs. Right now it is empty because your project uses nothing extra.

Update Rust

Rust releases new versions every six weeks. To update to the latest version at any time, run:

rustup update

Rustup downloads and installs the new version automatically.

Setup Summary

Step 1: Install rustup  →  gets you rustc and cargo too
Step 2: Verify install  →  rustc --version and cargo --version
Step 3: Pick an editor  →  VS Code + rust-analyzer recommended
Step 4: New project     →  cargo new your_project_name
Step 5: Stay updated    →  rustup update (run whenever you like)

Leave a Comment