2 minute read

When you first start with Rust, it is usually much easier to install everything through the official installer, rustup, instead of installing the compiler by itself. This post walks through the most basic setup flow on Windows with VS Code, ending with a simple Hello, world! program.

Where to Find the Official Installer

You can find the official Rust install page and the rustup site here:

In practice, “installing Rust” usually means installing rustup. Once rustup is installed, you also get rustc, cargo, the standard library, and toolchain management.

How to Install Rust on Windows

The basic installation flow on Windows is:

  1. Open the official site above.
  2. Download rustup-init.exe for Windows.
  3. Run the installer.
  4. When the menu appears, choose 1) Proceed with standard installation.
  5. Open a new PowerShell or Command Prompt window after installation finishes.
  6. Check that the install worked with the commands below.
rustc --version
cargo --version

If the installation completed successfully, you should see version information like this. The exact version numbers will vary depending on when you install.

Check rustc version

Check cargo version

If you plan to work with Rust in VS Code, it is a good idea to install the rust-analyzer extension as well. It makes autocomplete, diagnostics, and editor feedback much more convenient.

Create a new folder, open it in VS Code, then make a hello.rs file with the following code:

fn main() {
    println!("Hello, world!");
}

This is the most basic starting point in Rust. The main function is the entry point of the program, and println! prints a string to the console.

Build with rustc

If you want to test a single file quickly, you can compile it directly with rustc.

First, save the code below as hello.rs.

fn main() {
    println!("Hello, world!");
}

Then move to that folder in PowerShell and build it like this:

rustc hello.rs

After the build finishes, a hello.exe file will be created in the same folder. Run it with:

.\hello.exe

If everything worked, the output will be:

Hello, world!

Build with cargo

For real projects, you will usually create and manage everything with cargo. It handles project generation, builds, execution, and dependency management.

Start by creating a new project:

cargo new hello-rust
cd hello-rust

This creates a src/main.rs file. Put the following code in that file:

fn main() {
    println!("Hello, world!");
}

Now build the project with:

cargo build

When the build finishes, the executable will be created at target\\debug\\hello-rust.exe. You can run it directly with:

.\target\debug\hello-rust.exe

Or, if you want to build and run in one step, use:

cargo run

The result is the same:

Hello, world!

Wrap-up

The most common way to install Rust is through the official tool, rustup. For quick experiments, rustc can be enough, but real development is much smoother with a cargo project. A good first step is to get Hello, world! running and then become familiar with commands like cargo run, cargo build, and cargo check.

댓글남기기