Introduction
Before writing Rust code, you need to install the Rust toolchain. The recommended way is via rustup, the official installer and version manager, which sets up both rustc (the compiler) and cargo (Rust's build tool and package manager). Cargo handles compiling your code, managing dependencies (called crates), running tests, and creating new projects with a standard folder structure.
Cricket analogy: Installing rustup is like a young player joining the BCCI academy system: one registration (rustup) gives you the coach (rustc compiler) and the kit manager (cargo) who tracks gear, arranges nets, and organizes matches.
Syntax
# Install Rust via rustup (Linux/macOS)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Verify the installation
rustc --version
cargo --versionExplanation
The rustup script installs rustc, cargo, and the standard library, and also lets you manage multiple toolchain versions (stable, beta, nightly) and target platforms. Once installed, rustc --version and cargo --version confirm the toolchain is on your PATH and report the installed versions. From there, cargo new creates a new project with a Cargo.toml manifest file and a src/main.rs entry point; cargo build compiles the project, and cargo run compiles and immediately executes it.
Cricket analogy: Running rustc --version and cargo --version is like checking a player's registration card at the toss to confirm they're eligible; cargo new then sets up the standard scoreboard and lineup sheet (Cargo.toml, src/main.rs) before cargo run starts the innings.
Example
# Create a new binary project called 'hello_rust'
cargo new hello_rust
cd hello_rust
# Build the project
cargo build
# Build and run the project in one step
cargo runOutput
Compiling hello_rust v0.1.0 (/path/to/hello_rust)
Finished dev [unoptimized + debuginfo] target(s) in 0.42s
Running `target/debug/hello_rust`
Hello, world!Key Takeaways
- rustup is the official tool for installing and managing Rust toolchain versions.
- rustc is the Rust compiler; cargo is the build tool and package manager.
- cargo new scaffolds a new project with a Cargo.toml manifest and src/main.rs entry point.
- cargo build compiles the project; cargo run compiles and executes it in one step.
- rustc --version and cargo --version confirm a successful installation.
Practice what you learned
1. What is the recommended tool for installing Rust?
2. Which command creates a new Rust project with a standard folder structure?
3. What does cargo run do?
4. Which command checks that rustc is correctly installed and shows its version?
Was this page helpful?
You May Also Like
Introduction to Rust Programming
A beginner-friendly overview of Rust, a systems programming language built for memory safety and speed.
Cargo and Crates in Rust
Understand Cargo, Rust's build system and package manager, and how crates and Cargo.toml/Cargo.lock manage dependencies.
Features of Rust
An overview of the core language features that make Rust safe, fast, and productive to use.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics