Peter Girnus

View Original

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.

See this content in the original post

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.

See this content in the original post

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

See this content in the original post

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.

See this content in the original post

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.

See this content in the original post

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.

See this content in the original post

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.

See this content in the original post

How to check the version of rustup

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

See this content in the original post

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.

See this content in the original post

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.

See this content in the original post

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

See this content in the original post

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

See this content in the original post

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

See this content in the original post

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

See this content in the original post

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.

See this social icon list in the original post