Introcution
The Rust programming language is powerful general-purpose programming language.
It is syntactically similar to C++ and is used for a wide range of software development projects, including browser components, game engines, and operating systems.
Pre-requisites
Ubuntu 20,04 machine sudo enabled root user
Step 1 – Installaing RUST
Using the Rustup tool
$ sudo curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh .... Output sharique@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/sharique/.rustup This can be modified with the RUSTUP_HOME environment variable. The Cargo home directory is located at: /home/sharique/.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/sharique/.cargo/bin This path will then be added to your PATH environment variable by modifying the profile files located at: /home/sharique/.profile /home/sharique/.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 >
You can select option 1 to do setup RUST as default option.
Add rust tool chain directory into PATH environment
source $HOME/.cargo/env
Step 2 – Verifying Installation
rustc --version .... Output sharique@ubuntu:~$ rustc --version rustc 1.66.1 (90743e729 2023-01-10)
Step 3 – Installing Compiler
The GNU Compiler Collection (gcc
) in the build-essential
package includes a linker.
$ sudo apt update .... $ sudo apt upgrade .... $ sudo apt install build-essential
Step 4 – Creating, Compiling and Running RUST Program.
Creating directories to store the test scripts.
sudo mkdir ~/rustprojects .... cd ~/rustprojects .... mkdir testdir .... cd testdir
$ sudo nano test.rs
Copy the following code into test.rs
and save the file
test.rs
fn main() { println!("Congratulations! Your Rust program works."); }
Compiling the code
rustc test.rs
Run
./test
.... Output .... sharique@ubuntu:~/rustprojects/testdir$ ./test Congratulations! Your Rust program works. sharique@ubuntu:~/rustprojects/testdir$
Step 5 – Basic RUST Commands
Update RUST
rustup update
To Uninstall RUST
rustup self uninstall
Step 5 – Finale
Now we have installed RUST and tested Rust on Ubuntu 20.04