How To

Install Scala on RHEL 10 / Ubuntu 24.04

Scala is a modern programming language that runs on the Java Virtual Machine (JVM). It combines object-oriented and functional programming in a statically typed language, making it a strong choice for building scalable backend services, data pipelines, and distributed systems. Scala powers frameworks like Apache Spark, Akka, and Play Framework.

Original content from computingforgeeks.com - post 10144

This guide covers installing Scala 3.8.2 on RHEL 10, Rocky Linux 10, AlmaLinux 10, and Ubuntu 24.04. We walk through two installation methods – the recommended Coursier approach and manual tarball installation – plus setting up sbt (Scala Build Tool) and creating your first project.

Prerequisites

Before starting, make sure you have the following:

  • A server or workstation running RHEL 10, Rocky Linux 10, AlmaLinux 10, or Ubuntu 24.04
  • Root or sudo access
  • Internet connectivity to download packages
  • Java 11 or later (we install this in Step 1)

Step 1: Install Java (JDK)

Scala runs on the JVM, so a Java Development Kit is required. OpenJDK 17 or 21 are the best choices for Scala 3.x. If you already have Java installed, skip to Step 2.

On RHEL 10 / Rocky Linux 10 / AlmaLinux 10:

sudo dnf install -y java-21-openjdk-devel

On Ubuntu 24.04:

sudo apt update
sudo apt install -y openjdk-21-jdk

Confirm that Java is installed and available in your PATH.

java -version

The output should show the OpenJDK version you just installed:

openjdk version "21.0.6" 2025-01-21 LTS
OpenJDK Runtime Environment (build 21.0.6+7-LTS)
OpenJDK 64-Bit Server VM (build 21.0.6+7-LTS, mixed mode, sharing)

Coursier is the recommended way to install Scala and manage Scala tools. The cs setup command installs the Scala compiler, REPL, and related tools in one step. This is the method endorsed by the official Scala project.

Download and run the Coursier installer:

curl -fL "https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz" | gzip -d > cs
chmod +x cs
./cs setup -y

The installer adds Scala tools to ~/.local/share/coursier/bin and updates your shell profile. Load the new PATH in your current session:

source ~/.profile

Verify that Scala is accessible:

scala -version

You should see the Scala 3 version in the output:

Scala code runner version 3.8.2 -- Copyright 2002-2026, LAMP/EPFL

You can clean up the downloaded installer file:

rm -f cs

Step 3: Install Scala Manually from Tarball

If you prefer a manual installation or need Scala available system-wide for all users, download the official tarball from GitHub releases.

SCALA_VERSION="3.8.2"
wget https://github.com/scala/scala3/releases/download/${SCALA_VERSION}/scala3-${SCALA_VERSION}-x86_64-pc-linux.tar.gz

Extract the archive to /usr/local:

sudo tar -xzf scala3-${SCALA_VERSION}-x86_64-pc-linux.tar.gz -C /usr/local/
sudo ln -sf /usr/local/scala3-${SCALA_VERSION}/bin/scala /usr/local/bin/scala
sudo ln -sf /usr/local/scala3-${SCALA_VERSION}/bin/scalac /usr/local/bin/scalac

Verify the installation works:

scala -version

The version output confirms Scala is installed system-wide:

Scala code runner version 3.8.2 -- Copyright 2002-2026, LAMP/EPFL

Clean up the downloaded archive:

rm -f scala3-${SCALA_VERSION}-x86_64-pc-linux.tar.gz

Step 4: Install sbt (Scala Build Tool)

sbt is the standard build tool for Scala projects. It handles dependency management, compilation, testing, and packaging. If you used Coursier in Step 2, sbt is already installed. Otherwise, install it manually.

On RHEL 10 / Rocky Linux 10 / AlmaLinux 10:

Add the sbt repository and install:

sudo rm -f /etc/yum.repos.d/bintray-rpm.repo
curl -L https://www.scala-sbt.org/sbt-rpm.repo | sudo tee /etc/yum.repos.d/sbt-rpm.repo
sudo dnf install -y sbt

On Ubuntu 24.04:

Add the sbt APT repository and install:

echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/sbt.gpg
sudo apt update
sudo apt install -y sbt

Confirm sbt is installed by checking its version:

sbt --version

The first run downloads required components, then displays the version:

sbt version in this project: 1.12.6
sbt script version: 1.12.6

Step 5: Verify Scala Installation

Run a quick check to confirm all components are working together. Verify that both scala and scalac (the compiler) are available:

scala -version
scalac -version

Both commands should return version 3.8.2. Also verify Java is detected:

java -version

If any of these fail, check that your PATH includes the Scala binary directory. For Coursier installations, ensure ~/.local/share/coursier/bin is in your PATH.

Step 6: Scala REPL Basics

The Scala REPL (Read-Eval-Print Loop) lets you run Scala code interactively – useful for testing snippets and learning the language. Start it by typing scala without arguments:

scala

You enter the interactive Scala shell:

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

scala>

Try a few basic operations to confirm everything works:

scala> val greeting = "Hello from Scala"
val greeting: String = Hello from Scala

scala> println(greeting)
Hello from Scala

scala> val numbers = List(1, 2, 3, 4, 5)
val numbers: List[Int] = List(1, 2, 3, 4, 5)

scala> numbers.map(_ * 2)
val res0: List[Int] = List(2, 4, 6, 8, 10)

scala> :quit

The REPL supports tab completion, multi-line input, and all Scala 3 features including functional programming patterns like pattern matching and higher-order functions.

Step 7: Create Your First Scala Project with sbt

The fastest way to start a new Scala 3 project is using the sbt new command with the official Scala 3 template. Create a project directory and initialize it:

sbt new scala/scala3.g8

When prompted, enter a project name (for example, hello-scala). sbt creates the project structure:

hello-scala/
  ├── build.sbt
  ├── project/
  │   └── build.properties
  └── src/
      ├── main/
      │   └── scala/
      │       └── Main.scala
      └── test/
          └── scala/
              └── MySuite.scala

The build.sbt file contains the project configuration including the Scala version and dependencies. The src/main/scala/Main.scala file contains a sample application.

Open the main source file to see the generated code:

cat hello-scala/src/main/scala/Main.scala

The default template generates a simple application:

@main def hello(): Unit =
  println("Hello world!")
  println(msg)

def msg = "I was compiled by Scala 3. :)"

Step 8: Compile and Run Your Scala Application

Navigate into the project directory and use sbt to compile and run the application:

cd hello-scala
sbt run

sbt downloads dependencies on the first run, then compiles and executes the application. You should see the output from Main.scala:

[info] compiling 1 Scala source to /home/user/hello-scala/target/scala-3.8.2/classes ...
[info] running hello
Hello world!
I was compiled by Scala 3. :)
[success] Total time: 5 s

Other useful sbt commands for development:

  • sbt compile – compile without running
  • sbt test – run unit tests
  • sbt console – open REPL with project dependencies loaded
  • sbt package – create a JAR file
  • sbt ~run – recompile and re-run on every file change

Scala 2 vs Scala 3 – Key Differences

Scala 3 (codenamed Dotty) is a major redesign of the language. If you are migrating from Scala 2, here are the most significant changes:

FeatureScala 2Scala 3
SyntaxBraces required for blocksOptional braces (indentation-based syntax)
Implicitsimplicit keyword (complex)given/using clauses (clearer intent)
EnumsSealed trait + case objects patternNative enum keyword
Type systemPath-dependent typesUnion types, intersection types, opaque types
MacrosScala 2 macros (experimental)Redesigned macro system (stable)
Entry pointdef main(args: Array[String])@main annotation
Trait parametersNot supportedTraits can have parameters

Scala 3 maintains backward compatibility with most Scala 2 libraries through the TASTy interchange format. You can use Scala 2 dependencies in Scala 3 projects without issues in most cases. The Gradle build tool also supports Scala projects as an alternative to sbt.

Conclusion

You now have Scala 3.8.2 and sbt installed on your Linux system, ready for development. The Coursier method is the easiest to maintain and update, while the manual tarball approach works better for shared servers where system-wide installation is needed.

For production Scala applications, set up a proper CI/CD pipeline with Jenkins or GitHub Actions, configure proper JVM memory settings with -Xmx flags, and use sbt assembly or sbt-native-packager to build deployable artifacts.

Related Articles

Books Master Web Design in 2026: Top Books for Beginners & Experienced Designers Desktop How To Install Arduino IDE on Linux Linux Mint How To Install IntelliJ IDEA on Linux Mint 22 Programming Best JavaScript Books for 2024: From Beginner to Advanced

Leave a Comment

Press ESC to close