There are too many programming languages nowadays and each one with a specific role. If we explore each of the languages, we will realize that not all of them are multi-purpose. Instead, each one focuses on a certain area of technology. However, every day a language that has found great support from programmers becomes more relevant. This post is about how to install Rust on Debian 10.
What is Rust?
Rust is a programming language created by Mozilla and driven by the user and contributor community. The first stable version dates from 2015 so we are talking about a relatively new but powerful and stable language.
On the other hand, Rust is open-source because it is released under the MIT and Apache licenses. It also has binaries for Linux, Windows, and macOS. So the operating system will not be limiting for the developer.
Although it may not seem like it, Rust is the programming language most loved by developers. At least according to surveys conducted by the popular site StackOverflow that brings together many developers worldwide.
In general, Rust is designed to develop system software, where the interaction with the user is practically null. However, this does not mean that it cannot be used to develop other types of applications.
Where does Rust come from and why is it so important?
Rust arises as a particular need of Mozilla. As we know, Firefox had lagged behind Google Chrome in speed. That’s when Mozilla decided to create a new rendering engine that could improve load times, but not only that but also memory management.
The solution might seem simple to use C++. But it was quickly discarded because it had a memory management flaw. That is to say, it is very fast but for being a key component of a web browser, it did not work.
So, Mozilla decided to create a programming language that would be fast enough but would allow for up-to-date tools. It’s also pertinent to say that it was not only Mozilla that pushed the language but also the community played a fundamental role in this.
This situation makes us wonder why language is so important. First of all, Rust is an important part of Firefox which makes it used indirectly by many users.
Also, Rust is an essential part of Dropbox’s data centers. Yes, Dropbox the giant in cloud storage services. Just like Yelp has created an A/B testing framework.
So Rust is here to stay and why not, in the future we could place it next to C++ as the references for speed and robustness for very large systems.
Install Rust on Debian 10
Once you know what Rust is, or at least the fundamentals of the language. You probably need to install it, and for that, we will use Debian 10 because it is a system very used by developers.
First, open a terminal and install the compiler for C on Linux called GCC.
:~$ sudo apt install gcc
You will probably also need the full set of tools for package creation in Debian 10. In that case, you can install them with the following command:
:~$ sudo apt install build-essentials
This will not only install GCC but other packages as well.
The main reason for this is that Rust uses GCC as a linker for the compiler itself. Also, it assumes that you already have it installed, but it is better to be safe and avoid problems during compilation.
Rust is installed by running a script that you can get by using the curl command. However, it is also possible that curl is not installed on the system. So do it.
:~$ sudo apt install curl
Thanks to curl we can download the installation script. Everything as simple as executing a command.
So, to download and run the installation script for Rust on Debian 10, run this command:
:~$ curl https://sh.rustup.rs -sSf | sh
As soon as you run it you will see a text that tells you what the installer will do. As you can see, the installer will install the language, along with its compiler and a package manager called cargo. Also, it will indicate the directories where it will install.
At the end of the screen output, it will show you 2 installation options. I recommend using the default installation (option 1) because it is faster, easier, and does not give problems.
Then, the download and installation will start. In the end, you will see an image like this.
All that remains is to update the cargo and rust profile file. This so you can execute the rust commands from anywhere on the prompt.
:~$ source $HOME/.cargo/env
Testing Rust on Debian 10
The installation has been a success but we must check that everything is correct. First of all, you can find out the version of Rust installed by running the following command:
:~$ rustc --version
The best buy is to create a Rust file and run it.
So first create the necessary directory structure
:~$ mkdir -p test/example/
In this case, the test
folder is the project folder and example
is where the source code file will be. Access the folder:
:~$ cd test/example/
And within it, create a new text file with your favorite editor. In this case, I will use the terminal and the nano
editor.
:~$ nano helloworld.rs
Now add some Rust content. For example, a Hello World.
fn main() { println!("Hello World!!!"); }
Save the changes and exit the editor.
Now proceed to compile the source code using the Rust compiler.
:~$ rustc helloworld.rs
And finally, run it with the following command:
:~$ ./helloworld
Now you are completely sure that Rust is correctly installed and works great.
Finally, you can check the Rust help from the terminal.
:~$ rustc --help
Conclusion
Learning a programming language can be a good idea in this day and age. And to limit programming to Python, Java, or C++ is not to see the full picture that computer science offers us today.
In this context, Rust has been with us for a few years now but it has been enough to show us its power. Besides being open source, it has very powerful features for automated systems.
Only time will tell us what will become of Rust, but everything points to the fact that it will become more important every day. So it is convenient to learn how to install it in Linux and concretely in Debian 10 that is a system very used by the developers.