Scala Tutorial
Basics
Control Statements
OOP Concepts
Parameterized - Type
Exceptions
Scala Annotation
Methods
String
Scala Packages
Scala Trait
Collections
Scala Options
Miscellaneous Topics
To install Scala on a Linux system, you can use package managers or manually install from the official distribution. Below are the steps for both approaches:
First, ensure that Java is installed on your system, since Scala runs on the Java Virtual Machine (JVM):
sudo apt update sudo apt install default-jdk
Install Scala:
sudo apt install scala
Install Java:
sudo dnf install java-latest-openjdk
Install Scala:
sudo dnf install scala
The process might vary depending on the distribution. If Scala is available in the official repositories, you can use the system's package manager to install it.
Ensure Java is installed. You can download and install it from the official Oracle website or use OpenJDK based on your preference.
Download the latest Scala distribution from the official Scala website.
Extract the downloaded archive:
tar -xvzf scala-<version>.tgz
Move the extracted directory to a location like /opt
:
sudo mv scala-<version> /opt/scala
Add the Scala binaries to your PATH
. You can do this by adding the following lines to your ~/.bashrc
or ~/.zshrc
(depending on your shell):
export SCALA_HOME=/opt/scala export PATH=$PATH:$SCALA_HOME/bin
Reload your shell or execute:
source ~/.bashrc
or
source ~/.zshrc
SDKMAN! is a tool for managing multiple versions of software development kits. It makes installing Scala (and other SDKs like Java, Groovy, etc.) very easy.
Install SDKMAN!:
curl -s "https://get.sdkman.io" | bash
Then, open a new terminal or:
source "$HOME/.sdkman/bin/sdkman-init.sh"
Install Scala:
sdk install scala
This will install the latest stable version of Scala. If you need a specific version, you can specify it in the install command.
After installation, you can verify that Scala was installed correctly by running:
scala -version
This should display the version of Scala that you installed.
Scala installation steps for Linux:
# Download Scala distribution wget https://downloads.lightbend.com/scala/2.13.8/scala-2.13.8.tgz # Extract the archive tar -xzvf scala-2.13.8.tgz # Move Scala to a desired location sudo mv scala-2.13.8 /usr/local/ # Add Scala bin directory to PATH export PATH=$PATH:/usr/local/scala-2.13.8/bin # Verify installation scala -version
Installing Scala with a package manager on Linux:
sudo apt-get update sudo apt-get install scala
Configuring PATH for Scala on Linux:
export PATH=$PATH:/usr/local/scala-2.13.8/bin
Checking Scala installation on Linux:
scala -version
Managing Scala versions on Linux:
sdkman
or coursier
to manage multiple Scala versions on your system.sdkman
:curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk version
sdkman
:sdk install scala 2.13.8