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.
![Online Rust Compiler Online Rust Compiler](/sites/tutorial2program/files/programiz-compiler-rust-getting-started.png)
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.
![Rust Download Page Rust Download Page](/sites/tutorial2program/files/rust-download-page.png)
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 Installer Prompt Rust Installer Prompt](/sites/tutorial2program/files/getting-started-with-rust-installer-prompt.png)
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.
![Rust Installation Options on Windows Rust Installation Options on Windows](/sites/tutorial2program/files/rust-installation-options-windows.png)
After a short wait, you'll see a message confirming the successful installation of Rust.
![Rust Successful Installation Rust Successful Installation](/sites/tutorial2program/files/rust-successful-installation.png)
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
![Rust Installation Verification for Windows Rust Installation Verification for Windows](/sites/tutorial2program/files/rust-installation-verify.png)
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)"
![Homebrew Installation on Mac Homebrew Installation on Mac](/sites/tutorial2program/files/getting-started-Rust-homebrew-installation-mac1.png)
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.
![Rust Installation on Mac Rust Installation on Mac](/sites/tutorial2program/files/getting-started-Rust-installation-mac1.png)
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
![Rust Installation Verification for Mac Rust Installation Verification for Mac](/sites/tutorial2program/files/getting-started-Rust-installation-verify-mac1.png)
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
![Install curl on Ubuntu Install curl on Ubuntu](/sites/tutorial2program/files/install-curl-ubuntu.png)
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
![Install Rust on Ubuntu Install Rust on Ubuntu](/sites/tutorial2program/files/install-rust-ubuntu.png)
Step 4: Install GNU Compiler Toolchain
To install GNU compiler toolchain, run the following command:
sudo apt install build-essential
![Install build- essential package on Ubuntu Install build- essential package on Ubuntu](/sites/tutorial2program/files/install-build-essential-ubuntu.png)
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
![Rust Installation Verification for Linux Rust Installation Verification for Linux](/sites/tutorial2program/files/rust-installation-verify-for-linux.png)
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.
![Create a New File in VS Code Create a New File in VS Code](/sites/tutorial2program/files/create-new-file-for-rust.png)
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.
![Rust-Analyzer Extension in VSCode Rust-Analyzer Extension in VSCode](/sites/tutorial2program/files/install-rust-analyzer-extension-vs-code.png)
Similarly, search for the Code Runner extension,
![Code Runner Extension in VSCode Code Runner Extension in VSCode](/sites/tutorial2program/files/install-code-runner-extension-vs-code.png)
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.
![Run Rust Program on VS Code Run Rust Program on VS Code](/sites/tutorial2program/files/run-rust-program.png)
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.