For users, especially developers wanting to try out the Rust Programming language, the following tutorial will teach you how to import and install the latest version on Ubuntu 22.10 Kinetic Kudu, 22.04 Jammy Jellyfish, or 20.04 Focal Fossa Linux LTS.
What is Rust Programming Language?
Rust Programming Language is a modern language with an innovative approach to safety and performance. Rust enables developers to develop programs that are both reliable and fast in execution. The language contains type safety, memory safety, and support for low-level programming, making it an excellent choice for system-level software development. This feature has introduced the first groundwork in the Linux kernel 6.1 to be written with Rust, and its usage will increase in the later Linux Kernel release versions.
Note about the Tutorial
The following tutorial was done with a Ubuntu 22.10 release, and example images were taken. Still, it was tested on Ubuntu 22.04 and 20.04 LTS releases and worked correctly. In the future, if Ubuntu makes any changes to break the tutorial for one of the distribution versions, please place a comment for me to investigate so I can update the tutorial.
Recommended Steps Before Installation
First, update your system to ensure all existing packages are up to date to avoid potential conflict issues during the installation.
First, update your system to ensure all existing packages are up to date.
sudo apt update
Optionally, you can list the updates for users who require review or are curious to see what is available to update. This can be good if you have a specific you forgot to place; use the apt-hold command.
sudo apt --list upgradable
Proceed to upgrade any outdated packages using the following command.
sudo apt upgrade
Install Rust on Ubuntu
Install Dependencies
Before proceeding further, run the following command to install the required packages needed to install and successfully run Rust on your system. The packages are well known and highly used amongst many similar types of installations.
sudo apt install curl build-essential gcc make -y
Once you have completed the required installation of packages in prerequisites, you can now use (the curl command) to download the Rust installation script by executing the following command.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Next, you should see an output like the example below with a prompt about installing the default or customizing the installation.
Type 1 and press the ENTER KEY to continue unless you want to customize.
The installation should take 1 to 5 minutes, depending on your server’s internet speed and hardware.
Note you will need to activate the (Rust environment) for your current shell once the installation is complete. This is done using the following command, which will also be in your terminal output at the end of the installation.
source "$HOME/.cargo/env"
Verify the version build of Rust installed, which will show you it is successfully installed.
rustc -V
Example output:
rustc 1.66.0 (69f9c33d7 2022-12-12)
Note that you have not activated the Rust environment shell if you cannot print out the version build.
Create Rust Sample Project Application
So you have installed Rust and believe it should be working correctly. When installing a programming language on your operating system, the best way to verify is to create a quick test application.
You will make the famous (Hello World) output using Rust for the tutorial.
First, you must create a directory that will serve as a (Workspace).
mkdir ~/rust-projects
Secondly, change the directory to the Workspace and create a sample application with the following command.
cd rust-projects && nano helloworld.rs
Next, enter the following code for the hello world test.
fn main() {
println!("Hello World, this is a test provided by Computing post.com");
}
Save and close CTRL+O, exit CTRL+X, and compile the program with the following command.
rustc helloworld.rs
This will create an executable application after it has finished compiling. The application will be in your current directory, as shown in the example output below.
ls
To run the application you created using Rust, run the program with the execute command:
./helloworld
Additional Commands & Tips
Update Rust
Rust can be updated easily as it has its updater built in. So, updating Rust is relatively easy and is done with a simple command in your terminal.
rustup update
Remove (Uninstall) Rust
If, in the future, you no longer require Rust on your Ubuntu operating system, run the following command, which will remove the Rust Programming Language installation with its own uninstall script.
rustup self uninstall
Note you will be prompted with the following message in your terminal.
This will uninstall all Rust toolchains and data, and remove
$HOME/.cargo/bin from your PATH environment variable.
Continue? (y/N)
Example output:
Type Y and press the ENTER KEY.
You will then get the following result Rust has been successfully removed from your system.
Conclusion
In the tutorial, you have learned how to install Rust programming language on Ubuntu using the official Rust installation script and create a test application to ensure the installation is working correctly on your system.