How to Install Rust on Ubuntu?

Share your love by sharing

Rust is a general purpose programming language that is somewhat similar to C++. Rust is used in the development of many softwares which includes gaming engines, browsers and Operating Systems. In this tutorial, we will see how to install Rust on Ubuntu.

How-to-Install-Rust-on-Linux
How-to-Install-Rust-on-Linux

Prerequisites

Step 1 – Installing Rust on Ubuntu using rustup tool

There are many ways to install Rust but we recommend installation using rustup tool.
Execute the given command and Rust’s latest version

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

Output

ashish@ubuntu:~$ curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/sammy/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/sammy/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /home/sammy/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/sammy/.profile
  /home/sammy/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>
Note: Here we are using the default option 1. If you want to customize your installation, you can proceed with option 2

Output

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2023-01-10, rust version 1.66.1 (90743e729 2023-01-10)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
67.4 MiB / 67.4 MiB (100 %) 40.9 MiB/s in 1s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
6.6 MiB / 6.6 MiB (100 %) 5.5 MiB/s in 1s ETA: 0s
info: installing component 'clippy'
info: installing component 'rust-docs'
19.1 MiB / 19.1 MiB (100 %) 2.4 MiB/s in 7s ETA: 0s
info: installing component 'rust-std'
30.0 MiB / 30.0 MiB (100 %) 5.6 MiB/s in 5s ETA: 0s
info: installing component 'rustc'
67.4 MiB / 67.4 MiB (100 %) 5.9 MiB/s in 11s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

stable-x86_64-unknown-linux-gnu installed - rustc 1.66.1 (90743e729 2023-01-10)

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"
ashish@ubuntu:~$

Execute the below command to add Rust directory to PATH variable

$ source $HOME/.cargo/env

Step 2 – Verify the Installation

Lets verify the Rust installation by checking the version.

$ rustc --version

Output

ashish@ubuntu:~$ rustc --version

rustc 1.66.1 (90743e729 2023-01-10)

Step 3 – Installing Compiler

Rust needs a compiler to join the output to one file. If left uninstalled you may get the following error

error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

So, lets install the package, but before that lets update the apt packages

$ apt update
$ apt upgrade

Install build-package package

$ sudo apt install build-essential

Step 4 – Creating important directories

Final step is to create some important directories

$ mkdir ~/rustprojects
$ cd ~/rustprojects
$ mkdir testdir
$ cd testdir

Thats all, now you can start preparing your codes.

Share your love by sharing
Sourabh Verma
Sourabh Verma

I.T Engineer by profession, tech lover. Passionate for reading and writing technical stuffs. Loves to share knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *