Rust is a system programming language supported widely across all major operating systems.
You can run Rust using the following two methods:
- Run Rust online
- Install Rust on your computer
In this tutorial, you will learn both methods.
Run Rust Online
To run Rust code, you need to have a Rust compiler installed on your system. However, if you want to start immediately, you can use our free online Rust editor.
The online editor enables you to run Rust code directly in your browser—no installation is required.
Install Rust on Your Computer
For those who prefer to install Rust on their computer, this guide will walk you through the installation process on Windows, macOS, or Linux (Ubuntu).
To install Rust on your Windows, just follow these steps:
- Install VS Code
- Download the Rust Installer
- Run the Rust Installer
- Install Rust
- Verify the Installation
Here is a detailed explanation of each of the steps:
Step 1: Install VS Code
Go to the VS Code Official website and download the Windows installer. Once the download is complete, run the installer and follow the installation process.
Click Finish to complete the installation process.
Step 2: Download the Rust Installer
Go to the official Rust website and download the latest version for Windows.
The website automatically detects your operating system and gives you the correct installer.
Step 3: Run the Rust Installer
Now, go to your download folder and run the installer you just downloaded.
Step 4: Install Rust
Once you run the installer, you'll see the following screen where Rust asks for Microsoft C++ Build Tools to compile certain projects.
Rust on Windows uses two toolchains: MSVC and GNU. Don't worry about the technical details—this tutorial will guide you through the simpler GNU toolchain.
When prompted, simply press
y
and hit
Enter
to continue.
Next, you'll come across the installation options. For the standard setup, just press Enter, and the installation will start.
After a short wait, you'll see a message confirming the successful installation of Rust.
Step 5: Verify the Installation
After the installation is complete, verify whether Rust is installed by using the following command in the command prompt.
rustc --version
Note: The version number might differ from the one above, depending on your installed version.
Now, you are all set to run Rust programs on your device.
To install Rust on your Mac, just follow these steps:
- Install VS Code
- Check Rust Version
- Install Homebrew (if not installed)
- Install Rust
- Verify the installation.
Here is a detailed explanation of each of the steps:
Step 1: Install VS Code
Go to the VS Code official website and download the zipped file. Once the download is complete, open the zipped file.
In Finder, open a new window and navigate to the Applications folder. Drag the VS Code application from the zip file into the Applications folder to install it.
You can now launch VS Code directly from the Applications folder.
Step 2: Check Rust Version
You can check if Rust is already installed by using the following command in the Terminal app:
rustc --version
If you are satisfied with the installed version, you can skip the remaining steps. Otherwise, follow the steps below.
Step 3: Install Homebrew
Homebrew is a package manager that simplifies the installation of software on macOS. Open the Terminal app and type the following command to install Homebrew (if it's not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
When this installation is complete, we will use homebrew to install Rust.
Step 4: Install Rust
Now that Homebrew is installed, you can easily install Rust. In the Terminal, enter the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This command downloads a script and starts the installation of the Rust toolchain. Follow the prompts in your terminal to complete the installation.
Step 5: Verify the installation
Once all the above processes are complete, exit the current terminal session and open up a new terminal session to verify installation.
To verify successful installation, run the following command:
rustc --version
Note: The version number might differ from the one above, depending on your installed version.
Linux has various distributions, and the installation process differs slightly from each other. For now, we will focus on Ubuntu.
To install Rust, follow these steps:
- Install VS Code
- Install Curl
- Install Rust
- Install gcc Compiler Toolchain
- Verify the Installation
Here is a detailed explanation of each of the steps:
Step 1: Install VS Code
Open the Terminal and type:
sudo apt update
This command updates your package lists to ensure you get the latest versions of your software.
Proceed to install VS Code with:
sudo snap install code --classic
Step 2: Install Curl
Before we install Rust, we'd need to install Curl. You can install curl using the following command in the terminal window.
sudo apt install curl
When this installation is complete, we will use curl to install Rust.
Step 3: Install Rust
Now, proceed with the following curl command to install Rust.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Step 4: Install GNU Compiler Toolchain
To install GNU compiler toolchain, run the following command:
sudo apt install build-essential
This will install everything you require to run Rust programs locally on your computer.
Step 5: Verify Installation
Once all the above processes are complete, exit the current terminal session and open up a new terminal session to verify installation.
To verify successful installation, run the following command:
rustup -v
Now, you are all set to run Rust programs on your device.
Run Your First Rust Program
First, open VS Code, click on the File in the top menu, and then select New File.
Then, save this file with a
.rs
extension by clicking on
File
again, then
Save As, and type your filename ending in
.rs
. (Here, we are saving it as
hello_world.rs
).
Before you start coding, make sure to install the rust-analyzer and Code Runner extensions in VS Code.
Open VS Code and click on Extensions on the left sidebar. Then, search for the rust-analyzer extension using the Rust Programming Language and click on Install.
Similarly, search for the Code Runner extension,
Now, write the following code into your file:
fn main() {
println!("Hello, World");
}
Then click on the run button on the top right side of your screen.
You should see
Hello, World
printed on the terminal.
Now that you have set everything up to run Rust programs on your computer, you'll be learning how the basic program works in Rust in the following tutorial.