Day 1: Getting Started with Rust – Installation and Overview of the Rust Ecosystem

Venkat Annangi
Venkat Annangi
13/09/2024 07:23 3 min read 85 views
#rust #108 days of rust

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

  1. Download the Rust installer from the official Rust website: https://rustup.rs/
  2. Run the installer and follow the on-screen instructions.
  3. Configure your terminal by running: set PATH=%PATH%;%USERPROFILE%\.cargo\bin
  4. Verify the installation with rustc --version.

Installing Rust on macOS

  1. Open your terminal and run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  2. Follow the instructions to complete installation.
  3. Run source $HOME/.cargo/env to configure your terminal.
  4. Verify installation with rustc --version.

Installing Rust on Linux

  1. Run the following command: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  2. Configure the terminal with source $HOME/.cargo/env.
  3. 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 and cargo 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:

  1. Run cargo new hello_rust to create a new project.
  2. Navigate to the project folder with cd hello_rust.
  3. Edit the src/main.rs file:
fn main() {
    println!("Hello, world!");
}
  1. Run the project with cargo run. You should see Hello, world! in your terminal.

That’s a detailed introduction to the Rust ecosystem. Stay tuned for Day 2!

Comments