AiViewz: Create and Share Your Content

Blogs, articles, opinions, and more. Your space to express and explore ideas.

Rust Programming Day 2: Installing Rust and Setting Up Your Development Environment

In Day 2: Installing Rust and Setting Up Your Development Environment of "Rusty Skills: Mastering Rust in 30 Days," you will learn how to install Rust and configure your development environment. We’ll walk you through the installation process using rustup, Rust's version manager, and show you how to set up Cargo, Rust's package manager. You’ll also get tips on choosing a text editor or IDE tailored for Rust development. By the end of this article, you’ll have your environment ready and your first Rust project up and running. Get ready to start coding in Rust!

Day 2: Installing Rust and Setting Up Your Development Environment

Objective

How to Install Rust in Linux?

By the end of this lesson, you will have Rust installed on your machine and a development environment configured to start writing Rust code.


1. Installing Rust

The recommended way to install Rust is through rustup, which manages Rust versions and associated tools. Here’s how to get started:

Step 1: Install rustup

  • Open your terminal (or command prompt) and run the following command to download and install rustup:
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
  • If you're using Windows, you can use PowerShell:
    Invoke-WebRequest -Uri https://sh.rustup.rs -UseBasicP -OutFile rustup-init.exe; .\rustup-init.exe
    

Step 2: Follow the prompts

  • The installer will guide you through the installation process. You can generally choose the default options.

Step 3: Update your PATH

  • After installation, you need to ensure that the Rust binaries are in your system's PATH. If you installed via rustup, this should be done automatically. If not, you might need to add the following line to your shell profile (e.g., .bashrc.zshrc, or .bash_profile):
    export PATH="$HOME/.cargo/bin:$PATH"
    

Step 4: Verify the installation

  • To confirm that Rust is installed correctly, run:
    rustc --version
    
    You should see the version of Rust you installed.

2. Installing Cargo

Cargo is Rust’s package manager and build system, included with the installation of Rust via rustup. It helps manage dependencies, compile packages, and more.

  • To verify that Cargo is installed, run:
    cargo --version
    

3. Setting Up Your Development Environment

Now that Rust and Cargo are installed, let’s set up a development environment.

Option 1: Use a Text Editor or IDE

You can choose any text editor or Integrated Development Environment (IDE) for Rust development. Here are some popular choices:

  • Visual Studio Code (VS Code): A popular, lightweight editor with excellent Rust support via extensions.
    • Install the Rust Analyzer extension for enhanced Rust support, including auto-completion, error checking, and more.

Option 2: Install Rust Language Support in Your Editor

  • For VS Code:

    1. Open VS Code and go to Extensions (Ctrl+Shift+X).
    2. Search for and install the Rust Analyzer extension.
  • For IntelliJ IDEA:

    1. Open IntelliJ and navigate to Plugins in the settings.
    2. Search for Rust and install the plugin.

4. Creating Your First Rust Project with Cargo

With Rust and Cargo installed, let’s create a simple project.

Step 1: Create a new Cargo project

  • Run the following command in your terminal:
    cargo new hello_cargo
    
    This command creates a new directory called hello_cargo with a simple project structure.

Step 2: Navigate to your project directory

  • Change to the newly created project directory:
    cd hello_cargo
    

Step 3: Build and run your project

  • You can build and run the project using Cargo:
    cargo run
    

You should see the output:

Hello, world!

This message comes from the src/main.rs file created by Cargo, which contains your main function.


5. Conclusion

Today, you learned how to install Rust and set up your development environment, including installing Cargo and creating your first Rust project. With these tools, you’re now ready to dive deeper into Rust programming.

Next Steps

In the next article, we’ll explore Rust’s basic syntax, including variables, data types, and control flow.

Comments

Please log in to add a comment.

Back to Home
Join Our Newsletter

Stay updated with our latest insights and updates