Install Scala 3 in RHEL 9 using Terminal

In this guide, you will learn to Install Scala 3 and Access Scala Shell in RHEL 9 including AlmaLinux 9 and Rocky Linux 9 by using the Terminal Command Line. Scala is a high-level, object-oriented, and general-purpose programming language that is based on Java. It can be used for Building Data-Intensive, Distributed Applications and Systems.

Scala 3 is the latest and complete version. You can follow the steps below to get the installation steps on RHEL 9.

If you are an Ubuntu user, you can get Scala by visiting Install Scala in the Ubuntu Terminal Command Line.

Learn To Install Scala 3 in RHEL 9 (AlmaLinux 9 and Rocky Linux) using Terminal

Before you start your Scala 3 installation, you must have access to your server as a non-root user with sudo privileges. For this purpose, you can visit the Orcacore website and get the RHEL 9 initial server setup guides such as AlmaLinux 9 and Rocky Linux 9.

In this guide, we use AlmaLinux 9 to show the installation steps. Proceed to the next steps to complete this guide.

Step 1 – Update RHEL 9 Server using Terminal

First, you must run the system update on your RHEL 9 server. To do this, you can run the commands below:

# sudo dnf makecache
# sudo dnf update

Now you can start to install the requirements for Scala 3 and get the latest version.

Step 2 – Installing Java for Scala 3 on RHEL 9

Because Scala is based on JVM, you must have Java installed on your server. To do this, you can run the command below to install Java and other requirements tools:

sudo dnf install -y wget gzip java-17-openjdk

Then, verify your Java installation by checking its version:

java --version
Output
openjdk 17.0.9 2023-10-17 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.9.0.9-1) (build 17.0.9+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.9.0.9-1) (build 17.0.9+9-LTS, mixed mode, sharing)

Step 3 – Get Scala Setup Installer on RHEL 9

At this point, you can use the following wget command to get the Scala installer script on your RHEL 9 server:

sudo wget https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz

Then, unzip your downloaded file with the following command:

sudo gunzip cs-x86_64-pc-linux.gz

Move your extracted file to the CS directory and make the file executable with the commands below:

# sudo mv cs-x86_64-pc-linux cs
# sudo chmod +x cs

Step 4 – Run Scala 3 Installer Setup Script on RHEL 9

Now you can easily run your Scala setup installer by using the following command in your Terminal:

sudo ./cs setup

It will check for your JVM files that are installed and ask you to add the path to the profile and bashrc. Enter Y to continue.

Output
Checking if a JVM is installed
Found a JVM installed under /usr/lib/jvm/java-17-openjdk-17.0.9.0.9-2.el9.x86_64.

Checking if ~/.local/share/coursier/bin is in PATH
  Should we add ~/.local/share/coursier/bin to your PATH via ~/.profile, ~/.bash_profile? [Y/n] Y

Checking if the standard Scala applications are installed
  Installed ammonite
  Installed cs
  Installed coursier
  Installed scala
  Installed scalac
  Installed scala-cli
  Installed sbt
  Installed sbtn
  Installed scalafmt

Next, apply the changes by sourcing the bash profile:

sudo source ~/.bash_profile

Now you should have Scala installed on your server. To verify it, you can check its version:

scala -version
Output
Scala code runner version 3.3.1 -- Copyright 2002-2023, LAMP/EPFL

As you can see, you have Scala 3 in the latest version on your RHEL 9 server.

Step 5 – Access Scala 3 Shell and Test it from RHEL 9 Terminal

At this point, you can access and run Scala from the RHEL 9 terminal. To do this, you can simply run the command below:

scala

In the output, you should see:

Output
Welcome to Scala 3.3.1 (17.0.9, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala>

To see if your Scala is working correctly, you can run a sample project. For example:

scala> println("Hello This is Orcacore Team!")
Hello This is Orcacore Team!

To exit from the Scala shell, you can type:

scala> q:

To get more information, you can visit the Scala Documentation.

Step 6 – Uninstall Scala with CS Installer From RHEL 9

If you no longer want to use Scala, you can simply use the CS installer setup to remove it. To do this, run the command below:

cs uninstall scala
Output
Uninstalled scala

Conclusion

Now you have learned to Install Scala 3 in the latest version with the CS setup installer on RHEL 9 including AlmaLinux 9 and Rocky Linux 9 by using the terminal command line. Also, you have learned access to your Scala shell and test your installation.

Hope you enjoy it. You may also like the following guides:

Install Ansible on AlmaLinux 9 / RHEL 9

Joomla CMS LTS with LAMP Stack on Debian 12

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!