DEV Community

Cover image for Tuts: RUST 101
Miguel N. RIvera
Miguel N. RIvera

Posted on

Tuts: RUST 101

This short tutorial is the first one of a series aimed at introducing beginners to new programming languages.

Rust is an advanced and robust programming language that prioritizes memory safety, concurrency, and performance.

For beginners looking to begin their journey with Rust, this short tutorial will provide a step-by-step guide on setting up Rust and creating your initial program.


Step 1: Install Rust

To begin, you'll need to install Rust on your machine. Visit the official Rust website at rust-lang.org and follow the installation instructions for your operating system.

The installation process should be straightforward and well-documented.

Step 2: Set Up Your Development Environment

Once Rust is installed, you must set up your development environment. Rust comes with a command-line tool called cargo, making creating, building, and managing Rust projects easy.

Open your terminal or command prompt and run the following command to verify that Rust is installed correctly:

$ rustc --version
Enter fullscreen mode Exit fullscreen mode

If you see the version number printed, you're good to go!

Step 3: Create a New Rust Project

Now, let's create a new Rust project. In your terminal or command prompt, navigate to the directory where you want to make your project. Run the following command to start a new project using cargo:

$ cargo new my_project
Enter fullscreen mode Exit fullscreen mode

This will create a new directory called my_project with the basic structure of a Rust project.

Step 4: Write Your First Rust Program

Navigate into the newly created my_project directory:

$ cd my_project

Enter fullscreen mode Exit fullscreen mode

Open the project in your favorite code editor and locate the src directory. Inside the src directory, you'll find a file named main.rs. This is where you'll write your first Rust program.

Open main.rs and replace the existing code with the following:

fn main() {
    println!("Hello, Rust!");
}
Enter fullscreen mode Exit fullscreen mode

Save the file.

Step 5: Build and Run Your Program

To build and run your program, go back to your terminal or command prompt and navigate to the root directory of your project (my_project). Run the following command to build your program:

$ cargo build

Enter fullscreen mode Exit fullscreen mode

If there are no errors, you should see a message indicating that the build was successful.

To run your program, enter the following command:

$ cargo run

Enter fullscreen mode Exit fullscreen mode

You should see the output. Hello, Rust! Printed in your terminal.


Step 6: Explore Further

Congratulations!

You've written and executed your first Rust program. You can continue exploring the Rust programming language from here by reading the official Rust documentation at https://www.rust-lang.org/learn/get-started.

Many online resources, tutorials, and books are available to help you get deeper into Rust and expand your knowledge.

That's it! You've completed the beginner's guide to Rust.

Top comments (0)