Rust Installation

Before we get started with our first Rust program, we need to install Rust on our system. In this lesson, we will learn how to install Rust on different operating systems.

Learn Rust by Practice

Master Rust through hands-on coding exercises and real-world examples.

Installing Rust on Linux and macOS

This approach is recommended by the Rust team. It is a command-line tool called Rustup that manages Rust versions and associated tools. Run this command in your terminal to install it:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

This will download the Rust installer and open the following screen in your terminal:

Rust linux install page Rust linux install page

Type 1 and press enter to install Rust with the default settings. After the installation is finished, restart your current shell or open a new terminal window.

We can then use the rustc command to see if Rust is installed. rustc stands for "Rust compiler", and it is used to compile Rust code. You can ensure Rust is installed by running:

rustc --version

Rustc Version Rustc Version

Installing Rust on Windows

In order to install Rustup on Windows, go to the official Rust website, you'll have 2 options to install Rust on Windows (32-bit and 64-bit). Choose the one that fits your system and download the installer.

Install Rustup Windows Install Rustup Windows

After the download is finished, run the installer and follow the instructions. You will see a screen like this:

Install Rustup windows Install Rustup windows

Type 1 in the terminal and press enter, this will install Rustup with the default settings.

Install C++ Build Tools, you also need to install the C++ build tools to compile Rust code on Windows. You can download the build tools from the official Microsoft website. After the download is finished, run the installer and follow the instructions, and make sure to select C++ build tools, Windows 10 SDK, and English pack components.

After the installation is done, open cmd.exe or PowerShell and run the following command:

rustc --version

Rust version in cmd Rust version in cmd

If you see the version of Rust, then you have successfully installed Rust on your system. If not, make sure to check the installation steps again.

Updating Rust

Rust releases new versions often, so it's a good idea to keep your Rust installation up-to-date. You can update Rust by running the following command:

rustup update

Uninstalling Rust

If you want to uninstall Rust from your system, you can run the following command:

rustup self uninstall

The Rust ecosystem

The Rust programming language provides many other developer tools to make working with Rust easier. When we ran the installed earlier, we also installed a few other tools that come with Rust. Here are the tools that are used with Rust:

  • Rustc: The Rust compiler, which is used to compile Rust code.
  • Cargo: The Rust package manager and build system, which is used to manage dependencies and build Rust projects. (We will be using Cargo a lot)
  • Rustup: The Rust toolchain installer, which is used to install and manage Rust versions.
  • Clippy: A collection of lints to catch common mistakes and improve your Rust code.
  • Rustfmt: A tool to format your Rust code according to the Rust style guidelines.
  • Rustdoc: A tool to generate documentation for your Rust code.

Setting up your IDE

  • Visual Studio Code (VS Code): With the Rust extension, it provides features like IntelliSense, code formatting, and debugging.
  • IntelliJ IDEA: With the Rust plugin, it offers code completion, refactoring, and debugging support.
  • CLion: A JetBrains IDE that supports Rust with the Rust plugin, providing smart coding assistance, debugger, and Cargo build system support.

There are other IDEs and text editors that support Rust development, like Sublime Text, Atom, and Emacs. You can choose the one that fits your needs.

Since VSCode is the most popular code editor, we will be using it with the Rust extension. You can install the Rust extension by searching for "Rust" in the extensions tab in VS Code.

Rust VSCode extension Rust VSCode extension

This extension pack also includes Rust analyzer, which provides features like code completion, diagnostics, and code navigation. Crates which helps you manage dependencies, and Rust Syntax for improved syntax highlighting.

Conclusion

In this section, we learned how to install Rust on different operating systems. We also learned how to update and uninstall Rust from our system. We learned about the Rust ecosystem and the tools that come with Rust and we set up our IDE for Rust development.


In the next section, we will write our first Rust program.