How to Install and Run Rust on Linux

Rust (commonly known as Rust-Lang) is a relatively new, open-source practical systems programming language that runs extremely fast, prevents segfaults, and guarantees thread safety. It is a safe and concurrent language developed by Mozilla and backed by LLVM.

It supports zero-cost abstractions, move semantics, guaranteed memory safety, threads without data races, trait-based generics, and pattern matching. It also supports type inference, minimal runtime as well as efficient C bindings.

Rust can run on a great number of platforms and is being used in production by companies/organizations such as Dropbox, CoreOS, NPM, and many more.

In this article, we will show how to install Rust programming language in Linux and set up your system to get started with writing programs with Rust.

Install Rust Programming Language in Linux

To install Rust, use the following official method of installing Rust via the installer-script, which requires a curl command-line downloader as shown.

$ sudo apt-get install curl  [On Debian/Ubuntu]
# yum install install curl   [On CentOS/RHEL]
# dnf install curl           [On Fedora]

Then install Rust by running the following command in your terminal, and following the onscreen instructions. Note that rust is actually installed as well as managed by the rustup tool.

$ curl --proto '=https' --tlsv1.2 -sSf | sh
Install Rust in Linux
Install Rust on Linux

Once the Rust installation is complete, the Cargo’s bin directory (~/.cargo/bin – where all tools are installed) will be added to your PATH environment variable, in ~/.profile.

During the installation rustup will attempt to add the cargo’s bin directory to your PATH; if this fails for one reason or another, do it manually to get started with using rust.

Add Rust Cargo Bin Directory to PATH
Add Rust Cargo Bin Directory to PATH

Next, source the ~/.profile file to use the modified PATH and configure your current shell to work with the rust environment by running these Linux commands.

$ source ~/.profile
$ source ~/.cargo/env

Finally, verify the version of rust installed on your system by running the following command.

$ rustc --version
Check Rust Installed Version in Linux
Check Rust Installed Version in Linux

Test Rust Programming Language in Linux

Now that you have rust installed on your system, you can test it by creating your first rust program as follows. Begin by creating a directory where your program files will reside.

$ mkdir myprog
$ cd myprog

Create a file called, copy and paste the following lines of code to the file.

fn main() {
    println!("Hello World, it’s – Best Linux HowTos, Guides on the Internet!");

Then run the following command which will create an executable called test in the current directory.

$ rustc

Finally, execute test as shown.

$ ./test 
Write Programs in Rust Language
Write Programs in Rust Language

Important: You should take note of these points about rust releases:

  • Rust has a 6-week rapid release process, be sure to get many builds of rust available at any time.
  • Secondly, all these builds are managed by rustup, in a consistent manner on every supported platform, enabling installation of rust from the beta and nightly release channels, and support for additional cross-compilation targets.

Uninstall Rust on Linux

If at any point you would like to uninstall Rust, you can:

# rustup self uninstall

In this article, we have explained how to install and use Rust programming language in Linux. Try it out and give us your feedback or share any queries via the comment form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.


Leave a Reply
  1. In the explanation above you indicate:


    Should not this be:


    Otherwise, I liked the instructions.


Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.