Installing and configuring
Setting Up the Rust Development Environment
Alright, let's get your computer ready to write some Rust code! The easiest and official way to install Rust is using rustup
.
-
Open Your Terminal/Command Prompt:
- Linux/macOS: Open your regular terminal application.
- Windows: Open PowerShell or Command Prompt. (If you're using VS Code, its integrated terminal works great!)
-
Install
rustup
:- Linux/macOS: Copy and paste this command into your terminal and press Enter. Follow the on-screen prompts (usually just pressing Enter for default options).
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Windows:
- Go to the official
rustup
download page: https://rustup.rs/ - Download the appropriate installer for your system (e.g.,
rustup-init.exe
for 64-bit Windows). - Run the installer and follow the instructions. Choose the default installation options.
- Go to the official
- Linux/macOS: Copy and paste this command into your terminal and press Enter. Follow the on-screen prompts (usually just pressing Enter for default options).
-
Configure Your Shell (Important for Linux/macOS):
- After
rustup
finishes on Linux/macOS, it will often tell you to run a command to add Rust to your system'sPATH
. This is usually:source "$HOME/.cargo/env"
- Run this command in your current terminal session. To make it permanent, you might need to add it to your shell's configuration file (like
.bashrc
,.zshrc
, or.profile
).
- Run this command in your current terminal session. To make it permanent, you might need to add it to your shell's configuration file (like
- After
-
Verify Installation:
- Close and reopen your terminal/command prompt (or run the
source
command). - Type these commands to check if Rust and Cargo (Rust's build tool, which comes with
rustup
) are installed correctly:rustc --version
cargo --version - You should see version numbers printed for both
rustc
(the Rust compiler) andcargo
. If you do, congratulations, Rust is installed!
- Close and reopen your terminal/command prompt (or run the
-
Install VS Code (Recommended IDE):
- If you don't have it already, download and install Visual Studio Code: https://code.visualstudio.com/
-
Install the
Rust Analyzer
Extension: This is crucial for a great Rust development experience in VS Code (code completion, error checking, formatting, etc.). Open VS Code, go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X), search for "Rust Analyzer", and install it. -
Install the
Slint
Extension: This is recommanded for a better development experience, featuring auto-complition, go-to definition, refactoring, syntax coloration, and a live preview and editing of Slint GUIs.