Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Rust Get Started


Get Started With Rust

At W3Schools, you can try Rust without installing anything.

Our Online Rust Editor runs directly in your browser, and shows both the code and the result:

Code:

fn main() {
  println!("Hello World!");
}

Result:

Hello World!
Try it Yourself »

Install Rust

However, if you want to download and install rust, you can go to rust-lang.org and follow the instructions there.

Or, if you are using the terminal, you can run:

curl https://sh.rustup.rs -sSf | sh

Check Installation

After installing, check if Rust is installed correctly by running:

rustc --version

The output will look something like this, depending on your version number:

rustc 1.86.0 (05f9846f8 2025-03-31)

Create a New Project

Use Cargo to create a new Rust project:

cargo new my_project

The output will look something like this:

    Creating binary (application) `my_project` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

This creates a folder called my_project with the following files:

  • Cargo.toml: Project settings
  • src/main.rs: Main Rust file

The main.rs file contains this default code:

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

Build and Run the Project

Next, write the following code to go into the project folder:

cd my_project

Then build and run the project:

cargo run

The output should be:

Hello, world!

Congratulations! You have just run your first Rust program.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.