Rust programming language was first released on July 7, 2010. At the time of writing, the latest stable release of Rust is 1.43.1. But, version 1.41.0 is available in standard Ubuntu repository. In this article, we would discuss how to install Rust in Ubuntu 20.04 LTS release.
Rust was designed by Graydon Hoare. The syntax of Rust programming language is pretty similar to that of C and C++.
We would first discuss the installation steps, then a Hello World program in Additional Info section.
Note: Following operations would require you to have superuser privileges. In case you don’t have one, then contact your System Administrator for assistance.
Install Rust in Ubuntu 20.04 LTS
Here, we would install version 1.41.0 – which is the latest version available at the time of writing in standard Ubuntu repository. Since, the package is already available in standard Ubuntu repository. Therefore, update the repository first to make the latest version of package available. Hence, issue the following in terminal –
sudo apt update
Next, to install Rust –
sudo apt install rustc
It will install related dependencies as well.
To verify for the version installed –
rustc -V
it would return with the output (or with the latest version available) –
rustc 1.41.0
In conclusion, we have discussed how to install Rust in Ubuntu 20.04 LTS release.
Additional Info –
In this section, we would discuss how to write and execute our first Hello World! code.
// This is single-line comment - ignored by compiler // main function fn main() { // when we compile the binary, following statements would get executed println!("Hello World!"); }
where,
println!() would print the text “Hello World!” without quotes in a new line.
Use nano text-editor or one you are comfortable with. Then, write and save the above code in a file. Do save the file with extension .rs
For instance –
first-code.rs
Now, compile the code with Rust compiler to generate the binary –
rustc first-code.rs
It would generate a binary first-code in the current directory. Then, execute the binary to get the desired output –
./first-code
We would get the following output in console –
Hello World!