DebianDebian Based

How To Install Scala on Debian 12

Install Scala on Debian 12

In this tutorial, we will show you how to install Scala on Debian 12. Scala, a powerful and versatile programming language, has gained significant popularity among developers due to its seamless integration with Java and its ability to handle both object-oriented and functional programming paradigms. As a result, many programmers are eager to learn and utilize Scala in their projects.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Scala programming language on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • Basic knowledge of Linux and familiarity with using the terminal.
  • You will need an active internet connection to download the Scala package.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Scala on Debian 12 Bookworm

Step 1. Update System Packages.

Keeping your system up-to-date is a fundamental practice in maintaining a secure and efficient operating environment. It ensures that you have the latest features, security patches, and software compatibility. To update your Debian 12 system, execute the following command in your terminal:

sudo apt update
sudo apt upgrade

This command first updates the list of available packages and their versions then upgrades the installed packages to their latest versions.

Step 2. Installing Java.

Before we dive into the installation process, it’s crucial to ensure that Java is installed on your system. Scala runs on the Java Virtual Machine (JVM), so having Java installed is a prerequisite. You can verify the installation by typing the following command in your terminal:

java -version

If Java is installed, the command will return the version of Java currently in use. If not, you’ll need to install it. You can do so by running:

sudo apt update
sudo apt install default-jdk

Step 3. Installing Scala on Debian 12.

Coursier is a tool that simplifies the installation of Scala. To install Coursier, use the following commands:

curl -fLo cs https://git.io/coursier-cli-linux
chmod +x cs
./cs setup

After installing Coursier, you can install Scala by running:

cs install scala

Once the installation is complete, you can verify it by checking the Scala version. Run the following command:

scala -version

If Scala is installed correctly, the command will return the version of Scala currently in use.

Step 4. Set Up a Scala Project.

Now that Scala is installed, let’s create a new Scala project. We’ll use sbt (Scala Build Tool), a build tool specifically designed for Scala projects. To create a new project, run:

cs install sbt

Then, create a new project:

sbt new scala/scala-seed.g8

This command will prompt you to name your project. The project structure will include a build.sbt file, which defines the project settings.

Step 5. Write a Simple Scala Program.

Let’s write a simple “Hello World” program in Scala. In your project directory, navigate to src/main/scala and create a new file named HelloWorld.scala. Add the following code:

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}

To compile and run the program, use sbt:

sbt run

Congratulations! You have successfully installed Scala. Thanks for using this tutorial to install the latest version of the Scala programming language on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Scala website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button