Installing Rust on Windows is a straightforward process, primarily accomplished using the installation tool rustup provided by Rust officially. Rust is a modern systems programming language, known for its memory safety and performance, suitable for developing applications such as operating systems, game engines, and web servers.
Installing Rustup
First, you need to download and run the Rustup installer. Open your browser, visit rustup.rs, and click the "Download" button on the page to get the installation file. Then, run the downloaded rustup-init.exe file as an administrator.
# Run rustup-init.exe in the terminal and follow the prompts
# Usually, selecting the default options (press Enter) is sufficient
Note: During the installation process, the system may prompt you to install Microsoft C++ build tools, which are necessary for compiling Rust code. Please ensure to install them; otherwise, subsequent compilations may fail.
Configuring Environment Variables
After installation, rustup will automatically add the Rust toolchain to the system's PATH environment variable. To ensure the configuration takes effect, you need to restart the terminal or command prompt. Open a new terminal window and enter the following commands to verify if the installation was successful.
rustc --version
cargo --version
If you see outputs similar to rustc 1.70.0 (90c541806 2023-06-03) and cargo 1.70.0 (ec8a8a0ca 2023-04-25), it indicates that Rust and its package manager Cargo have been installed correctly.
Creating a Project with Cargo
Cargo is Rust's build system and package manager, which simplifies project management. You can use Cargo to quickly create a new Rust project. In the terminal, navigate to the directory where you want to store the project, then run the following commands.
cargo new hello_world
cd hello_world
cargo run
This will create a new project named hello_world in the current directory and run it. You should see the output Hello, world! in the terminal.