How to install Scala on Ubuntu 22.04

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install Scala language on Ubuntu 22.04.

Scala is easily installed on Ubuntu 22.04 by using the official Scala installer that can be downloaded on your Ubuntu 22.04 machine and used to install the latest release of Scala via a simple command.

Step 1 - Download Scala Binary

To install Scala you need first to download Scala on your machine. To download Scala, you can use wget.

Simply run the following command, and Scala will be downloaded on your machine.

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

Step 2 - Extract Scala

Once you have downloaded Scala in the .gz file format, now you need to extract it. To extract Scala file that you downloaded, you can use the gzip command.

gzip -d cs-x86_64-pc-linux.gz

The command above, will extract the binary file that is compressed in a gzip file. Once you extract, you will see the binary file on your machine, this is the Scala's binary file called cs-x86_64-pc-linux

Step 3 - Install Scala

Now you can proceed to install Scala. To install Scala, first you need to make Scala's binary executable using the chmod command.

To make Scala binary executable, simply run the command below

chmod +x cs-x86_64-pc-linux

Now to install Scala, run the setup

./cs-x86_64-pc-linux setup

Next, scala installer will check if Java is installed on your system. If you don't have Java installed on your system, answer with Y on this step so scala downloads and installs it on your machine.

Answer with Yes on the second prompt so ~/.local/share/coursier/bin gets added on your Path

And Scala installer will now install Scala on your system, once setup is finished, you will see the following output on your terminal

Step 4 - Verify Scala Installation

Now before running scala, you can check scala version to verify that Scala was installed without any issues on your machine.

To check scala version, simply run the command below

scala --version

And it should show you scala version on your terminal. This means that Scala is working, and you should be able to use it.

If you can't run Scala, or when you try to run the command above doesn't work, then you need to make sure to add Scala on your Path.

You can manually do this, simply run the command below on your terminal

export PATH="$PATH:home/owlhowto/.local/share/coursier/bin"

replace owlhowto with your username

Once done, source your ~/.bashrc file so that changes take effect without having to log out of your system

source ~/.bashrc

Step 5 - Run Scala

Now you should be able to run Scala on your terminal

scala

Conclusion

In this tutorial, you learned how to install Scala programming language on your Ubuntu 22.04 machine, by using the official Scala installer.