The first question to ask is, what is Scala?
Scala is an object-oriented, general purpose programming language, which is also functional. Scala also supports static typing. Scala was designed to give a simple interface for functional programming while addressing the criticism aimed at Java. The code written in Scala is compiled to Java bytecode, which then runs on JVM. So Scala and Java are interoperable.
On the other hand, Scala offers some of the best known features of functional programming, including currying, type inference, immutability, and pattern matching. Higher-order types in Scala is also pretty awesome. People who have Java knowledge and have worked on other programming languages, such as PHP and NodeJS, would love to know that Scala has the best of all worlds. By this I mean that while Scala provides strong OO programming with the best of Java, it also includes features such as operator overloading, optional and named parameters, raw strings, and much more.
You can know more about Scala on the official website. Now let’s see how to install Scala on a Linux machine. Installing Scala is very easy:
- Download the latest version of Scala from here, ver. 2.12.2 as of this writing.
- Unzip it and place the folder wherever you want.
- Setup a couple of path variables in your .bashrc or .zshrc file, as below:
export SCALA_HOME="/home/sunny/Programs/scala-2.12.2" export PATH=$PATH:$SCALA_HOME/bin
That’s it. You’re done. Now open a new terminal window and type the following command:
You should see a prompt like this:
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131). Type in expressions for evaluation. Or try :help. scala>
If you get the “scala>” prompt, your installation was successful. You can type :help at the Scala prompt for a list of commands. You can type :quit or :q to exit the Scala CLI.