iTranslated by AI
Development Environment: Setting up Rust (MSVC) on Windows (2023 Edition)
tl;dr
- To develop in
Rust[1], you need to installVisual Studio Build Tools[2]. - Set up environment variables and install
Rustbased on those settings. - These steps can be performed efficiently using the
wingetcommand.
Introduction
To use the Rust programming language, a C++ compiler is required for compiling and building source code.
Rust for Windows requires either Visual C++ or GNU C++.
Therefore, you must set up a C++ development environment before installing Rust.
In this article, we will pre-install Visual Studio Build Tools, a software development tool from Microsoft that includes the Visual C++ compiler.
Installing Rust and Visual Studio Build Tools can be done easily using the winget[3] command.
winget is the official package manager for Windows, allowing you to install software in bulk from the command line.
This article provides a step-by-step explanation of how to install Rust and Visual Studio Build Tools.
1. Installing Visual Studio Build Tools
Rust requires a C++ compiler to function properly. To use Rust, we will pre-install Visual Studio Build Tools, Microsoft's software development tool suite that includes the C++ compiler.
For more details, please refer to the "Visual Studio Build Tools Installation Procedure Guide".
1.1. Installing Visual Studio Build Tools
Follow these steps to install Visual Studio Build Tools.
-
Launching
Visual Studio Installer:
Run the following command to launch theVisual Studio Installer.winget install Microsoft.VisualStudio.2022.BuildTools -
Selecting Components:
On the [Select Components] screen, select [Desktop development with C++].

-
Installing
Build Tools:
Click the [Install] button to install the selected components.

-
Closing
Visual Studio Installer:
Click the [×] in the upper right corner to exit the installer.
This completes the installation of Visual Studio Build Tools.
Next, we will configure the Path for the Visual Studio Build Tools.
1.2. Setting the Path
Follow these steps to set the Path.
-
Open the [System Properties] dialog:
Run the following command.systempropertiesadvanced.exeThe [System Properties] dialog will be displayed.

-
Open the [Environment Variables] dialog:
Click the [Environment Variables] button. The [Environment Variables] dialog will be displayed.

-
Edit the
Pathin [System variables]:
SelectPathunder "System variables" and click [Edit(I)].
The [Edit System Variable] dialog will be displayed.

-
Add the
C++compiler path:Click [New] and add the following
Path.Path Overview C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.36.32532/bin/HostX64/x64C++compiler -
Closing the dialogs:
Click [OK] and close all dialogs. -
Restart the PC:
Restart the PC to reflect the configuredPathin the environment.
This completes the setup for Visual Studio Build Tools.
2. Installing Rust
2.1. Setting Environment Variables
Below are the environment variables related to the installation and operation of Rust. By setting these variables before installation, you can specify the installation destination and other settings.
Below are the environment variables used by Rust and their settings.
| Environment Variable | Overview | Remarks |
|---|---|---|
CARGO_HOME |
Installation destination for Cargo
|
Installation destination for the Rust package manager Cargo. The Rust compiler and other tools will also be stored under this directory. |
Path |
Rust tool path |
Adds the Path for executing various Rust tools. |
RUSTUP_HOME |
Storage for various Rust data |
Stores various data such as the Rust toolchain, the compiler itself, and C headers and libraries. |
Configuring Environment Variables
Follow these steps to set the environment variables.
-
Open the [System Properties] dialog:
Run the following command.systempropertiesadvanced.exeThe [System Properties] dialog will be displayed.

-
Open the [Environment Variables] dialog:
Click the [Environment Variables] button. The [Environment Variables] dialog will be displayed.

-
Editing [System variables]:
Set the following environment variables in "System variables".Environment Variable Setting Remarks CARGO_HOMEc:\lang\rustIn my environment, various languages are stored under c:\lang.Path%CARGO_HOME%\binAdd the setting on the left to the Path. -
Editing [User variables]:
Set the following environment variables in "User variables".Environment Variable Setting Remarks RUSTUP_HOME%XDG_DATA_HOME%\rustupCorresponds to the XDG Base Directory[4]. -
Closing the dialogs:
Click [OK] on all dialogs to close them. -
Restart the PC:
Restart the PC to reflect the configuredPaththroughout the environment.
Environment variable setup is now complete.
2.2. Installing Rust
When installing Rust from the official website, Rustup[5], the installer for the Rust toolchain, is used.
Rustup also installs cargo and other toolchains necessary for software development in Rust.
It is a tool that allows you to manage, build, and update the entire Rust development environment.
winget packages include the Rust language and its installer Rustup.
This time, we will install the rustup package to use Rustup.
Below is a summary of the Rust language-related packages within winget.
Package ID |
Description | Remarks |
|---|---|---|
Rustlang.Rustup |
The Rust toolchain installer |
The installer for Rustup. Rust is automatically installed by the installed rustup. |
Rustlang.Rust.MSVC |
Rust (MSVC) |
The version of the Rust language that uses Visual C++ for C/C++ modules. |
Rustlang.Rust.GNU |
Rust (GNU) |
The version of the Rust language that uses GNU C++ for C/C++ modules. |
Follow these steps to install Rust.
-
Installing
rustup:
Run the following command inWindows Terminalto installRustup.winget install rustlang.rustup -
Installing
Rust:
rustupwill run automatically and installrust.rustupinfo: profile set to 'default' info: default host triple is x86_64-pc-windows-msvc info: syncing channel updates for 'stable-x86_64-pc-windows-msvc' . . ,
This completes the installation of Rust.
2.3. Checking Rust Operation
If the installation completed successfully, the Rust compiler rustc should be available.
Follow these steps to check the operation of rustc.
-
rustcversion:
Run the following command inWindows Terminal.rustc --version -
Checking the version:
Check if a version number like the following is displayed in theTerminal.rustc 1.71.0 (8ede3aae2 2023-07-12)
If a version number like (rustc 1.71.0 ...) is displayed, Rust has been successfully installed.
3. Verifying the Development Environment
To confirm that Rust has been installed correctly and that you can program with Rust, we will create a simple program that outputs Hello, World.
3.1. Hello, World in Rust
Follow these steps to verify your Rust development environment.
-
Navigate to the working directory:
OpenPowerShelland navigate to a suitable working directory for programming.cd ~/workspacies/temp/rust -
Creating
hello.rs:
Create ahello.rsfile and write the followingRustcode into it.// hello.rs fn main() { println!("Hello, rust World!") } -
Creating
hello.exe:
Compilehello.rsto createhello.exe.rustc hello.rs -
Running
hello.exe:
Runhello.exeand check if it works correctly.Hello, rust World!
If "Hello, rust World!" is output as shown above, Rust is working correctly.
Conclusion
By following the steps above, you can install the MSVC version of Rust in a Windows environment.
In summary, Rust can be installed through the following major steps:
- Before installing
Rust, installVisual Studio Build Tools, which includes the C++ compiler. - By setting environment variables in advance, you can freely change the installation destination of
Rust. - Use the
wingetcommand to easily installRust.
By performing these steps, you can smoothly build a Rust development environment.
Please use this article as a reference to set up your Rust development environment. Then, leverage your newly acquired Rust skills to further expand your world of engineering.
Happy hacking!
References
Websites
- Official Rust Website
- Rust Japanese Documentation
- Visual Studio Build Tools Installation Procedure Guide
XDG Base Directory
-
Rust: A system programming language that is fast, safe, and combines concurrency and practicality. It is characterized by a design that achieves both memory safety and high performance. ↩︎
-
Visual Studio Build Tools: A software development tool for cross-platform development provided by Microsoft. This is required for installing Rust. ↩︎ -
winget: The official Windows package manager. ↩︎ -
XDG Base Directory: A standard directory specification used for storing configuration files in Linux/UNIX. ↩︎ -
Rustup: The official tool for building and managing the Rust development environment. Usingrustupis recommended when setting up a Rust language development environment. ↩︎
Discussion