How to Easily Install Rust on WSL (Ubuntu 24.04)

Do you want to start programming with Rust? Rust is a modern programming language known for being fast, safe, and reliable. If you are a Windows user, a great way to develop with Rust is by using the Windows Subsystem for Linux (WSL).

This guide will show you the simple steps to install Rust on your computer using WSL, specifically with the new Ubuntu 24.04.

Step 1: Get Your System Ready

Before we install Rust, we need to make sure our Ubuntu environment has the necessary tools. Rust depends on a C compiler and other build utilities.

First, open your WSL Ubuntu 24.04 terminal. Then, run the following command to update your system's package lists:

sudo apt update && sudo apt upgrade -y

Next, install the build-essential package. This package includes the GCC compiler and other tools that Rust needs to work correctly.

sudo apt install build-essential -y

Now your system is ready for Rust!

Step 2: Install Rust with rustup

The official and easiest way to install Rust is by using a tool called rustup. rustup is the Rust installer and version manager.

To install Rust, copy and paste the following command into your terminal and press Enter:

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

The script will start and give you three options. For most users, the default option is the best choice.

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

Just press 1 and then hit Enter to continue with the standard installation.

After the installation is complete, you need to update your current shell's environment. Run this command:

source "$HOME/.cargo/env"

This command allows you to use Rust commands immediately without restarting your terminal.

Step 3: Check Your Installation

Let's make sure that Rust was installed correctly. You can check the version of the Rust compiler (rustc) and the Rust package manager (cargo).

Run this command to check the compiler version:

rustc --version

You should see an output similar to this (the version number might be newer):
rustc 1.78.0 (9b00956e5 2024-04-29)

Now, check the version of Cargo:

cargo --version

You should see an output like this:
cargo 1.78.0 (54a89d57b 2024-04-10)

If you see these version numbers, congratulations! Rust is successfully installed on your system.

Step 4: Create Your First Rust Project

Now for the fun part! Let's create a classic "Hello, World!" program to test that everything is working.

  1. First, create a new folder for your Rust projects.
    mkdir ~/rust_projects
    cd ~/rust_projects
  2. Next, use Cargo to create a new project called hello_world.
    cargo new hello_world
  3. Move into the new project directory.
    cd hello_world
  4. Finally, compile and run your program with a single command.
    cargo run

You will see the message Hello, world! printed in your terminal.

You have now successfully installed Rust on WSL with Ubuntu 24.04 and created your first program. You are all set to start your journey into Rust development. Happy coding!

Comments

Popular posts from this blog

Understanding Traits in Rust: More Than Just Interfaces

How to Install Ubuntu 24.04 WSL on Windows 10 and 11