Installing Scala on Linux
Introduction
Scala is a programming language with both imperative and functional capabilities. Scala home page is located here: www.scala-lang.org
This document explains how to install Scala command line compiler and other tools. To install Eclipse Scala IDE visit this page: Installing Eclipse Scala IDE on Linux
Prerequisites
Scala needs Java runtime to work. If you do not have Java installed follow these steps to install Java: Installing Open JDK on Linux
This document assumes you have root access to your Linux installation. If not you should install Scala somewhere in your home directory. Later on you can modify ~/.bashrc to add Scala executables folder to your PATH variable:
export PATH=/home/<user>/scala-2.10.3/bin:$PATH
Download and setup
Open this page in your browser in new window: www.scala-lang.org/download
Scroll down to Other ways to install Scala and click on the link below (Download the Scala binaries for unix). Choose Save File and save Scala archive to your Downloads folder. Current version is scala-2.13.2.tgz.
If you have root access:
cd /opt
mkdir scala
cd scala
mv /home/<user>/Downloads/scala-2.13.2.tgz .
tar xvf scala-2.13.2.tgz
rm scala-2.13.2.tgz
At this point you should see /opt/scala/scala-2.13.2 directory (owned by root user). Having a default link will help with upgrading Scala to a newer version later on. Once you download a new version you can remove that link and create another one with the same name but pointing to the new Scala installation directory.
cd /opt/scala
ln -s scala-2.13.2 default
Create links in /etc/alternatives:
cd /etc/alternatives
ln -s /opt/scala/default/bin/scala
ln -s /opt/scala/default/bin/scalac
ln -s /opt/scala/default/bin/scalap
ln -s /opt/scala/default/bin/scaladoc
Note Command ln usually takes two parameters (source file name and target file name) but if target file name is the same as the source file name you can skip the second parameter.
Create links in /usr/local/bin:
cd /usr/local/bin
ln -s /etc/alternatives/scala
ln -s /etc/alternatives/scalac
ln -s /etc/alternatives/scalap
ln -s /etc/alternatives/scaladoc
Check if Scala executable is visible:
which scala
// should print /usr/local/bin/scala
If that does not work check if /usr/local/bin is part of the default system path:
set | grep PATH
On my computer that command prints:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
If you do not see /usr/local/bin folder listed edit your /etc/profile file (as root user):
cd /etc
vi profile
// add this line at the end:
export PATH=/usr/local/bin:$PATH
Test Scala installation
Run those commands as your regular user:
cd
scala
You should see similar text printed to console:
Welcome to Scala 2.13.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_91).
Type in expressions for evaluation. Or try :help.
scala>
Press Ctrl+D
to exit Scala console.