Translate

Friday, 26 December 2025

how to install rust in widows

 

Step 1: Install Rust

On Windows, the standard way to install Rust is using rustup, a tool that manages Rust versions and associated tools.

Install rust in windows Vlr training


  1. Download the Installer:

  2. Run the Installer:

    • Double-click rustup-init.exe.

    • Crucial Note: The installer may ask you to install Visual Studio C++ Build Tools. If it does, follow the prompts to install them. Rust needs these Microsoft tools to link your programs correctly on Windows.

    • When prompted with installation options (1, 2, or 3), type 1 (Proceed with installation) and press Enter.

  3. Verify Installation:

    • Once the installation finishes, close your current command prompt/terminal and open a new one (Command Prompt or PowerShell).

    • Type the following to check if Rust is installed:

      PowerShell
      rustc --version
      
    • If you see something like rustc 1.75.0 (timestamp), you are ready to go!


Step 2: Write the "Hello, World!" Program

Rust files end with the .rs extension.

  1. Create a folder for your project (e.g., C:\RustProjects).

  2. Open a text editor (Notepad, Notepad++, or VS Code).

  3. Type the following code exactly as it appears:

Rust
fn main() {
    println!("Hello, world!");
}
  1. Save the file as main.rs inside your project folder.

Explanation of the code:

  • fn main() { ... }: This defines the main function. It is the entry point where your program begins executing.

  • println!("..."): This prints text to the console. The ! indicates that this is a macro, not a normal function (a key distinction in Rust).

  • ;: Almost all lines in Rust must end with a semicolon.


Step 3: Compile and Execute

Now you need to turn your text file into an executable program (.exe) that Windows can run.

  1. Open your terminal (Command Prompt or PowerShell).

  2. Navigate to the folder where you saved the file:

    PowerShell
    cd C:\RustProjects
    
  3. Compile the code using the Rust compiler (rustc):

    PowerShell
    rustc main.rs
    

    (If successful, nothing will happen in the terminal, but a main.exe and main.pdb file will appear in your folder.)

  4. Execute the program:

    PowerShell
    .\main.exe
    

Expected Output:

Plaintext
Hello, world!

Summary of Commands

GoalCommand
Check Versionrustc --version
Compilerustc filename.rs
Run (Windows).\filename.exe

No comments:

Post a Comment

Note: only a member of this blog may post a comment.