Install Rust Programming Language on AlmaLinux 9 – OrcaCore

Posted on

Install Rust Programming Language on AlmaLinux 9 - OrcaCore

Install Rust Programming Language on AlmaLinux 9 – OrcaCore

In this guide, brought to you by Orcacore, you will learn How To Install Rust Programming Language on AlmaLinux 9 and create a sample project to get you started. Rust was designed to offer high performance, rivaling that of C and C++, but with a strong focus on code safety, addressing the vulnerabilities often found in those languages. However, Rust’s benefits extend beyond just memory safety.

Rust provides high performance for processing large datasets, robust support for concurrent programming, and an efficient compiler. These advantages have led numerous software companies, from startups to large corporations like Firefox, Dropbox, and Cloudflare, to adopt Rust for production use.

To follow this guide, you’ll need a non-root user with sudo privileges on your server. If you haven’t already, you can set this up by following our guide on Initial Server Setup with AlmaLinux 9 on the Orcacore website.

Now, let’s proceed with the installation steps.

1. Install Rust on AlmaLinux 9

First, update your local package index using the following command:

sudo dnf update -y

Next, install the EPEL (Extra Packages for Enterprise Linux) repository on your server:

sudo dnf install epel-release -y

Install Dependencies for Rust Language

Install the necessary packages and dependencies using the following command:

sudo dnf install cmake gcc make curl -y

Download Rust Installer Script

Download the Rust installation script on your AlmaLinux 9 server:

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

You’ll see the following output:

[Image of Rust Installer Script prompt]

Enter 1 to proceed with the default installation.

Upon successful installation, you’ll receive the following output:

[Image of successful Rust installation]

Start Rust Environment

Initialize the Rust environment on AlmaLinux 9 using these commands:

# source ~/.profile
# source ~/.cargo/env

To verify that the Rust programming language is installed correctly, execute the following:

rustc -V
**Output**
rustc 1.65.0 (897e37553 2022-11-02)

Now that Rust is installed, let’s see how to use it.

2. Create a Sample Project with Rust Language

This section demonstrates how to use Rust on AlmaLinux 9 by creating a simple "Hello, World!" program.

First, create a directory for your Rust projects:

mkdir rust-projects

Then, navigate to the newly created directory:

cd rust-projects

Now, create a sample application using your preferred text editor (we’ll use vi here):

vi helloworld.rs

Add the following code to the file:

fn main() {
    println!("Hello World, this is a test provided by orcacore.com");
}

Save and close the file.

Compile the program using the following command:

rustc helloworld.rs

This command generates an executable application after compilation.

To run the application you created using Rust on AlmaLinux 9, execute the program:

./helloworld
**Output**
Hello World, this is a test provided by orcacore.com

3. Update Rust Programming Language

You can update your Rust installation with the following command:

rustup update
**Output**
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: checking for self-updates

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.65.0 (897e37553 2022-11-02)

info: cleaning up downloads & tmp directories

4. Remove Rust Programming Language

If you wish to remove Rust from your AlmaLinux 9 system, use the following command:

rustup self uninstall
**Output**
Thanks for hacking in Rust!

This will uninstall all Rust toolchains and data, and remove
$HOME/.cargo/bin from your PATH environment variable.

Continue? (y/N)

For more information, visit the Rust by Example page.

Conclusion

You have now successfully learned How To Install Rust Programming Language on AlmaLinux 9 and created a basic project. Rust’s robust safety features, concurrency support, and performance make it well-suited for a variety of applications, including system programming, web development, and embedded systems. The Install Rust Programming Language on AlmaLinux 9 guide provides a foundational understanding of the installation process.

Hope you enjoy it. You may also like these articles:

Install Apache Cassandra on AlmaLinux 9

How To Enable TCP BBR on AlmaLinux 8

How To Set up Golang on Debian 11


Alternative Solutions for Installing Rust on AlmaLinux 9

While the rustup tool is the recommended and most common method for installing Rust, here are two alternative approaches:

1. Using the dnf Package Manager Directly (Not Recommended)

AlmaLinux 9 may have Rust packages available in its repositories. However, this method is generally not recommended because the versions available in the repositories might be outdated. rustup always provides the latest stable (or beta/nightly) versions.

To check if Rust packages are available, you can use:

sudo dnf search rust

If Rust packages are found, you can install them using:

sudo dnf install rustc cargo

Explanation:

  • rustc: The Rust compiler.
  • cargo: The Rust package manager and build tool.

Important Considerations:

  • Version Control: Using dnf might install an older version of Rust, which might lack newer features or security patches.
  • Updates: Updates to Rust through dnf will be tied to the AlmaLinux release cycle, which might be slower than updates provided by rustup.
  • Multiple Versions: rustup allows you to easily switch between different Rust versions, a feature not readily available when installing via dnf.

Why it’s not recommended: The potential for outdated packages and lack of version management make this a less desirable approach compared to rustup.

2. Building from Source

Another alternative, though significantly more complex and time-consuming, is to build Rust from source. This method gives you the most control over the build process but requires more technical expertise. This method is usually reserved for very specific cases.

Steps:

  1. Download the Source Code: Obtain the source code from the official Rust website or GitHub repository.

  2. Install Dependencies: You’ll need a number of build tools and libraries. The specific dependencies will be outlined in the Rust documentation for building from source. This typically includes a C compiler (like GCC or Clang), Python, and various development libraries.

  3. Configure and Build: Use the build system (usually make or a similar tool) to configure and compile the source code. This can take a considerable amount of time, depending on your system’s resources.

  4. Install: Once the build is complete, install the compiled binaries to your system.

Example (Simplified and Highly Abridged – Consult Official Rust Documentation for Accurate Instructions):

# Assumes you have downloaded and extracted the Rust source code to a directory called 'rust-source'
cd rust-source

# You will likely need to install many more dependencies.
# These are examples, *not* a complete list.
sudo dnf install python3 gcc make

# Configure the build (check the Rust documentation for specific options)
./configure

# Build the source code (this will take a long time)
make

# Install the compiled binaries (requires root privileges)
sudo make install

Explanation:

  • ./configure: This script prepares the build environment. It checks for dependencies and sets up the build process based on your system.
  • make: This command executes the build process, compiling the source code into executable binaries.
  • sudo make install: This command installs the compiled binaries to the appropriate system directories, making them accessible from the command line.

Why this is complex:

  • Dependency Management: Ensuring you have all the necessary dependencies can be challenging.
  • Configuration: Configuring the build process correctly requires understanding the build system and available options.
  • Compilation Time: Building from source can take a significant amount of time, especially on less powerful systems.
  • Maintenance: Keeping the installation up-to-date requires manually repeating the build process for each new release.

When to use it:

Building from source is generally only necessary in specific situations:

  • Highly Customized Builds: When you need to modify the Rust compiler or standard library.
  • Specific Platform Support: When rustup doesn’t offer pre-built binaries for your specific architecture.
  • Educational Purposes: To gain a deeper understanding of the Rust build process.

In conclusion, while building from source offers maximum control, it’s generally more practical and convenient to use rustup for installing and managing Rust on AlmaLinux 9. It’s also important to note the difference between Install Rust Programming Language on AlmaLinux 9 using the recommended way and using deprecated methods.

Leave a Reply

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