Day 1: Getting Started with Rust – Installation and Overview of the Rust Ecosystem
Welcome to Day 1 of my #108DaysOfRust journey! In this blog post, I will walk through the basics of Rust, how to install it on different platforms (Windows, macOS, and Linux), and introduce key tools like Rustup, Cargo, and rustc. By the end of this post, you'll have Rust set up and understand how these components come together to create a powerful, developer-friendly environment for building safe and high-performance applications.
What is Rust?
Rust is a modern systems programming language that combines the performance of low-level languages like C and C++ with memory safety, making it perfect for building reliable, high-performance applications. Rust’s ownership model ensures memory safety without needing a garbage collector, making it a favorite for developers building systems-level software, game engines, and even web applications.
How to Install Rust
Rust uses a toolchain installer called rustup
, which makes it easy to install, update, and manage Rust versions on your system. Here’s how to get Rust installed on different platforms.
Installing Rust on Windows
- Download the Rust installer from the official Rust website: https://rustup.rs/
- Run the installer and follow the on-screen instructions.
- Configure your terminal by running:
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
- Verify the installation with
rustc --version
.
Installing Rust on macOS
- Open your terminal and run:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Follow the instructions to complete installation.
- Run
source $HOME/.cargo/env
to configure your terminal. - Verify installation with
rustc --version
.
Installing Rust on Linux
- Run the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Configure the terminal with
source $HOME/.cargo/env
. - Verify the installation with
rustc --version
.
What is Rustup?
rustup
is a tool that helps manage Rust versions and toolchains. It allows you to install, update, and switch between different versions of Rust. Think of it as a package manager for the Rust language and its associated tools.
When you install Rust using rustup
, it installs several key components:
- rustc: The Rust compiler that compiles your code.
- Cargo: Rust’s package manager and build system.
- Standard Library: Essential functionality for I/O, data structures, and more.
What is rustc
?
rustc
is the Rust compiler that turns your Rust source code into machine code (binary files) that can run on your system. For example:
rustc main.rs
./main
What is Cargo?
Cargo is Rust’s package manager and build system. It manages dependencies, builds your code, runs tests, and simplifies the entire project lifecycle.
- Project Creation: Create new Rust projects with Cargo.
- Dependency Management: Use
Cargo.toml
to manage dependencies. - Building & Running: Use
cargo build
andcargo run
to compile and execute. - Testing: Run tests with
cargo test
.
How Do Rustup, rustc, and Cargo Work Together?
These three tools form the core of the Rust development workflow:
- Rustup manages Rust versions and toolchains.
- rustc compiles Rust source code into machine code.
- Cargo simplifies project creation, builds, and dependency management.
Creating Your First Rust Project
Let’s create a simple "Hello, world!" project using Cargo:
- Run
cargo new hello_rust
to create a new project. - Navigate to the project folder with
cd hello_rust
. - Edit the
src/main.rs
file:
fn main() {
println!("Hello, world!");
}
- Run the project with
cargo run
. You should seeHello, world!
in your terminal.