Install Rust on Windows: From the Terminal

Easily Install Rust on Windows 10 or Windows 11. I will show you how to install Rust without an installer using the Windows Package Manager (winget) to install Rust with rustup, the Rust toolchain, and the necessary dependencies such as Visual Studio build tools and Desktop development with C++ tool set. Once installed, we will compile a rust program to demonstrate a successful installation!

Installing Rust on Windows Steps

The following section will outline the steps required to install the Rust programming language on Microsoft Windows through the Windows Package Manager (winget) tool.

Installing Visual Studio Build Tools

We must first install the visual studio build tools to use Rust on Windows. We can use winget to search for the Visual Studio Build Tools with the following command.

winget search buildtools

We are interested in the latest version of Visual Studio build tools and the Desktop development with C++ feature set, which we can install from the command-line with the following command.

winget install Microsoft.VisualStudio.2022.Community --silent --override "--wait --quiet --add ProductLang En-us --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended"

Once the installation is completed, restart Microsoft Windows with the following command.

shutdown -r

Searching for Rustup Toolchain Installer

To install Rust for Windows 10 or Windows 11, we need to first search for the Rustup installer. Rust is installed and managed by the rustup tool. We can search for the Rust packages in the winget repository using the following Windows or PowerShell terminal command.

winget search rustlang

The winget package we are interested in is the Rustlang.Rustup package.

Install Rust Windows, Through Winget

To install the Rust programming language on Microsoft Windows 10 or Windows 11, open the Windows Terminal or a PowerShell terminal and run the following command.

winget install Rustlang.Rustup

All the Rust development tools will be installed under C:\Users\<USERNAME>\.cargo\bin. The Full Rust toolchain includes tools such as:

  • rustc - the Rust compiler

  • cargo - the Rust package manager

  • rustup - the Rust toolchain manager

During rustup installation, the system PATH variable will be modified to include C:\Users\<USERNAME>\.cargo\bin in the PATH environment variable.

Once the installation is complete, we can run the following command to refresh our Windows environment variables to access the Rust toolchain.

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

Once the Rust toolchain is in our Windows environment path variable, we can call each tool individually.

How to check the Rust Compiler Version

To check the version of the rust compiler, you can use the rustc --version command.

rustc --version

How to check the version of rustup

To check the version of rustup you can use the rustup --version command.

rustup --version

How to check the version of Rust cargo?

To check the version of the rust package manager cargo, you can use the cargo --version command.

cargo --version

Write Your First Rust Program on Windows: Compiler Test

To demonstrate that we can write and compile Rust code, create a directory and navigate into this directory.

mkdir hello-world
cd hello-world

Next, open up a main.rs file inside this directory using the following command.

notepad main.rs

Once main.rs is open, add the following hello world example inside our main.rs file.

fn main() {
    println!("Hello, world!");
}

Now you can save and close this file and call the rust compiler for Windows with the following command.

rustc .\main.rs

If the program is compiled successfully, you can run the main.exe file.

./main.exe

Which will output our hello world example. Nice! You've successfully compiled your first Rust program congrats :)

Wrapping Up: Installing Rust on Windows 

In conclusion, this tutorial showed you how to install Rust on Windows 10 or Windows 11 systems using the Windows Package Manager (winget). We've demonstrated how effortless it is to install the Rust programming language directly from the Windows Terminal using rustup to install the entire Rust toolchain and the necessary dependencies such as Visual Studio build tools and the Desktop development with C++ toolchain.

Previous
Previous

Windows bashrc File: PowerShell Equivalent

Next
Next

Rust Reqwest Crate - GET JSON Object