Initial Setup
Want to start programming in Rust? This initial setup guide gets Rust installed and working on your system in minutes. By the end, you’ll have Rust running and will execute your first program.
This tutorial provides 0-5% coverage - just enough to get Rust working on your machine. For deeper learning, continue to Quick Start (5-30% coverage).
Prerequisites
Before installing Rust, you need:
- A computer running Windows, macOS, or Linux
- Administrator/sudo access for installation (Windows/Linux)
- A terminal/command prompt
- A text editor (VS Code, IntelliJ IDEA, Vim, or any editor)
- Basic command-line navigation skills
- A C compiler (macOS/Linux - we’ll verify this)
No prior systems programming experience required - this guide starts from zero.
Learning Objectives
By the end of this tutorial, you will be able to:
- Install rustup (Rust toolchain installer)
- Verify Rust compiler (rustc) and Cargo (build tool) installation
- Create a new Rust project with Cargo
- Write your first Rust program (Hello, World!)
- Compile and run Rust code
Rust Installation via rustup
rustup is the official Rust toolchain installer and version manager.
Windows Rust Installation
Step 1: Install Visual Studio C++ Build Tools
Rust on Windows requires MSVC (Microsoft Visual C++) build tools.
- Download Visual Studio Build Tools
- Scroll to “All Downloads” → “Tools for Visual Studio”
- Download “Build Tools for Visual Studio 2022”
- Run the installer
- Select “Desktop development with C++”
- Click Install (this takes 10-20 minutes)
Alternative: Install via winget
winget install Microsoft.VisualStudio.2022.BuildToolsStep 2: Download and Run rustup-init.exe
- Visit https://rustup.rs/
- Download
rustup-init.exefor Windows - Run the downloaded file
- You’ll see a command prompt with options:
1) Proceed with installation (default)
2) Customize installation
3) Cancel installationPress Enter (or type 1) to proceed with default installation.
Step 3: Wait for Installation
rustup downloads and installs:
- Rust compiler (rustc)
- Cargo (build tool and package manager)
- Standard library
- Documentation
Installation takes 5-10 minutes depending on internet speed.
Step 4: Verify Installation
Open new Command Prompt or PowerShell:
rustc --versionExpected output:
rustc 1.75.0 (82e1608df 2023-12-21)Also check Cargo:
cargo --versionExpected output:
cargo 1.75.0 (1d8b05cdd 2023-11-20)Troubleshooting Windows:
- If
rustcnot found, restart Command Prompt to load new PATH - Verify
%USERPROFILE%\.cargo\binis in PATH - If build tools missing, reinstall Visual Studio Build Tools
macOS Rust Installation
Step 1: Install Command Line Tools
Rust requires Xcode Command Line Tools (includes C compiler).
xcode-select --installIf already installed, you’ll see: “xcode-select: error: command line tools are already installed”
Step 2: Install Rust via rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shYou’ll see:
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
...
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>Press Enter to proceed with default installation.
Step 3: Configure PATH
The installer adds Rust to PATH via ~/.cargo/env. Load it:
source $HOME/.cargo/envOr restart your terminal.
Step 4: Verify Installation
rustc --versionExpected output:
rustc 1.75.0 (82e1608df 2023-12-21)Check Cargo:
cargo --versionExpected output:
cargo 1.75.0 (1d8b05cdd 2023-11-20)Troubleshooting macOS:
- If
rustcnot found, runsource $HOME/.cargo/env - Add to shell config for persistence:
echo 'source $HOME/.cargo/env' >> ~/.zshrc - Restart terminal after installation
Linux Rust Installation
Step 1: Install Build Dependencies
Rust requires a C compiler and linker.
Ubuntu/Debian:
sudo apt update
sudo apt install build-essentialFedora/RHEL/CentOS:
sudo dnf install gccArch Linux:
sudo pacman -S base-develStep 2: Install Rust via rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shYou’ll see installation options:
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>Press Enter for default installation.
Step 3: Configure PATH
Load Cargo environment:
source $HOME/.cargo/envOr restart terminal.
Step 4: Verify Installation
rustc --versionExpected output:
rustc 1.75.0 (82e1608df 2023-12-21)Check Cargo:
cargo --versionExpected output:
cargo 1.75.0 (1d8b05cdd 2023-11-20)Troubleshooting Linux:
- If build-essential missing, install it before rustup
- Ensure PATH includes
$HOME/.cargo/bin - Add to shell config:
echo 'source $HOME/.cargo/env' >> ~/.bashrc
Understanding rustup
rustup manages Rust toolchains, allowing multiple versions.
Check Installed Toolchains
rustup showOutput shows installed toolchain:
Default host: x86_64-unknown-linux-gnu
rustup home: /home/user/.rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu (default)
active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.75.0 (82e1608df 2023-12-21)Update Rust
Keep Rust up-to-date:
rustup updateDownloads and installs latest stable version.
Toolchain Channels
Rust has three channels:
- stable - Production-ready releases (6-week cycle)
- beta - Preview of next stable release
- nightly - Latest features (may be unstable)
Install a specific channel:
rustup install nightlySwitch default toolchain:
rustup default nightlyMost projects use stable channel.
Your First Rust Program (Manual)
Let’s write “Hello, World!” manually before using Cargo.
Create Source File
Create directory and file:
mkdir -p ~/rust-projects
cd ~/rust-projectsCreate hello.rs:
fn main() {
println!("Hello, World!");
}Code breakdown:
fn main()- Entry point function (every program starts here)println!- Macro to print text with newline (note the!)"Hello, World!"- String to print
Compile with rustc
Compile the source file:
rustc hello.rsThis creates executable:
- Windows:
hello.exe - macOS/Linux:
hello
Run the Program
Windows:
hello.exemacOS/Linux:
./helloOutput:
Hello, World!What happened:
- rustc compiled
hello.rsto native machine code - No runtime or virtual machine needed
- Executable runs directly on CPU
Create Your First Cargo Project
Cargo is Rust’s build tool and package manager. Most Rust projects use Cargo.
Create New Project
cargo new hello-rustOutput:
Created binary (application) `hello-rust` packageThis creates hello-rust/ directory:
hello-rust/
├── Cargo.toml # Project configuration
├── .gitignore # Git ignore rules
└── src/
└── main.rs # Main source fileExplore Project Structure
Navigate into project:
cd hello-rustView Cargo.toml:
cat Cargo.tomlContents:
[package]
name = "hello-rust"
version = "0.1.0"
edition = "2021"
[dependencies]This file defines:
- Package metadata (name, version, Rust edition)
- Dependencies (external libraries)
View src/main.rs:
cat src/main.rsContents:
fn main() {
println!("Hello, world!");
}Cargo generates a Hello World program automatically.
Build and Run with Cargo
Build the project:
cargo buildOutput:
Compiling hello-rust v0.1.0 (/path/to/hello-rust)
Finished dev [unoptimized + debuginfo] target(s) in 0.50sThis creates target/debug/hello-rust (or hello-rust.exe on Windows).
Run the executable:
./target/debug/hello-rustOutput:
Hello, world!Build and run in one step:
cargo runOutput:
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello-rust`
Hello, world!Cargo automatically rebuilds if source files changed.
Build for Release
Development builds include debug information. For optimized production builds:
cargo build --releaseOutput:
Compiling hello-rust v0.1.0 (/path/to/hello-rust)
Finished release [optimized] target(s) in 0.75sCreates target/release/hello-rust - smaller and faster than debug build.
Size comparison:
- Debug build: ~3-4 MB (includes debug symbols)
- Release build: ~300-400 KB (optimized, symbols stripped)
Performance: Release builds run significantly faster (10x+ for some code).
Modify the Program
Edit src/main.rs:
fn main() {
println!("Hello, Rust!");
println!("Welcome to systems programming.");
let x = 5;
let y = 10;
println!("{} + {} = {}", x, y, x + y);
}Run again:
cargo runOutput:
Compiling hello-rust v0.1.0 (/path/to/hello-rust)
Finished dev [unoptimized + debuginfo] target(s) in 0.45s
Running `target/debug/hello-rust`
Hello, Rust!
Welcome to systems programming.
5 + 10 = 15Code explanation:
let x = 5;- Declare immutable variablexprintln!("{} + {} = {}", x, y, x + y)- Format string with placeholders
Useful Cargo Commands
Check Code (Fast Compilation Check)
cargo checkChecks if code compiles without creating executable - much faster than cargo build.
Format Code
cargo fmtAutomatically formats code according to Rust style guide.
Run Linter (Clippy)
Install Clippy (if not already installed):
rustup component add clippyRun linter:
cargo clippyClippy suggests code improvements and catches common mistakes.
Generate Documentation
cargo doc --openGenerates HTML documentation for your project and opens in browser.
Run Tests
cargo testRuns all tests in your project (we’ll cover testing in later tutorials).
Clean Build Artifacts
cargo cleanRemoves target/ directory to free disk space.
Development Environment Setup
Several editors provide excellent Rust support.
VS Code with rust-analyzer
Step 1: Install VS Code
Download from https://code.visualstudio.com/
Step 2: Install rust-analyzer Extension
- Open VS Code
- Go to Extensions (Ctrl+Shift+X or Cmd+Shift+X)
- Search for “rust-analyzer”
- Click Install
Step 3: Open Rust Project
- File → Open Folder → Select
hello-rustdirectory - rust-analyzer automatically compiles project
- Get autocomplete, inline errors, and go-to-definition
rust-analyzer provides excellent IDE features for Rust.
IntelliJ IDEA with Rust Plugin
Step 1: Install IntelliJ IDEA
Download Community Edition from https://www.jetbrains.com/idea/download/
Step 2: Install Rust Plugin
- Open IntelliJ IDEA
- File → Settings → Plugins
- Search for “Rust”
- Install and restart IDE
Step 3: Import Project
- File → Open → Select
hello-rustdirectory - IDE detects Cargo project automatically
- Full IDE features: refactoring, debugging, profiling
Vim/Neovim with rust.vim
Vim users can use rust.vim plugin:
" Add to .vimrc or init.vim
Plug 'rust-lang/rust.vim'Enable auto-formatting on save:
let g:rustfmt_autosave = 1For advanced IDE features, use coc-rust-analyzer with CoC.
Verify Your Setup Works
Let’s confirm everything is functioning correctly.
Test 1: Rust Compiler
rustc --versionShould show rustc version 1.70 or later.
Test 2: Cargo
cargo --versionShould show cargo version.
Test 3: Create and Run Project
cargo new test-project
cd test-project
cargo runShould compile and print “Hello, world!”
Test 4: Release Build
cargo build --release
./target/release/test-projectShould run optimized executable.
Test 5: Code Formatting
cargo fmtShould format code (no errors).
All tests passed? Your Rust setup is complete!
Summary
What you’ve accomplished:
- Installed rustup (Rust toolchain installer)
- Installed Rust compiler (rustc) and Cargo build tool
- Verified installation with version checks
- Wrote and compiled your first Rust program manually
- Created and ran Rust projects with Cargo
- Built optimized release executables
- Understood Cargo project structure and workflow
Key commands learned:
rustc --version- Check Rust compiler versioncargo --version- Check Cargo versionrustup update- Update Rust to latest versioncargo new <name>- Create new projectcargo build- Compile projectcargo run- Build and run projectcargo build --release- Build optimized executablecargo check- Check code without buildingcargo fmt- Format code
Skills gained:
- Rust toolchain installation and management
- rustc manual compilation understanding
- Cargo project creation and management
- Debug vs release build awareness
- Rust development workflow basics
Next Steps
Ready to learn Rust syntax and concepts?
- Quick Start (5-30% coverage) - Touch all core Rust concepts in a fast-paced tour
Want comprehensive fundamentals?
Prefer code-first learning?
- By-Example Tutorial - Learn through heavily annotated examples
Want to understand Rust’s design philosophy?
- Overview - Why Rust exists and when to use it
Troubleshooting Common Issues
“rustc: command not found” (Linux/macOS)
Problem: Rust not in PATH.
Solution:
- Run
source $HOME/.cargo/envin current terminal - Add to shell config:
echo 'source $HOME/.cargo/env' >> ~/.bashrc - Restart terminal
“rustc: command not found” (Windows)
Problem: Rust not in PATH.
Solution:
- Restart Command Prompt or PowerShell
- Verify
%USERPROFILE%\.cargo\binin PATH - Reboot computer if PATH changes don’t take effect
“linker cc not found” (Linux)
Problem: C compiler not installed.
Solution:
- Install build-essential:
sudo apt install build-essential(Ubuntu/Debian) - Or install gcc:
sudo dnf install gcc(Fedora) - Recompile after installing compiler
“linker link.exe not found” (Windows)
Problem: Visual Studio C++ Build Tools not installed.
Solution:
- Install Visual Studio Build Tools with “Desktop development with C++”
- Reinstall rustup after installing build tools
- Restart computer
Cargo build is slow
Problem: First build downloads dependencies and compiles everything.
Solution:
- First build takes time (normal behavior)
- Subsequent builds much faster (incremental compilation)
- Use
cargo checkfor faster compilation checking - Release builds take longer due to optimizations
“Permission denied” running executable (Linux/macOS)
Problem: Executable doesn’t have execute permission.
Solution:
- Cargo-built executables have correct permissions automatically
- For rustc-built executables:
chmod +x ./hello
Outdated Rust version
Problem: Old Rust version installed.
Solution:
- Update via rustup:
rustup update - Check version after update:
rustc --version - rustup updates all components (rustc, cargo, std)
Further Resources
Official Documentation:
- The Rust Programming Language Book - Official comprehensive tutorial
- Rust by Example - Learn through examples
- Rustlings - Small exercises to get started
- Rust Standard Library Docs - Complete API reference
Interactive Learning:
- Rustlings - Interactive exercises
- Exercism Rust Track - Practice problems with mentorship
- Rust Playground - Try Rust in browser without installation
Books:
- The Rust Programming Language (Free online)
- Programming Rust - O’Reilly, comprehensive
- Rust in Action - Manning, practical approach
Community:
- Rust Users Forum - Community help and discussion
- /r/rust - Reddit Rust community
- Rust Discord - Real-time chat
- This Week in Rust - Weekly newsletter