Scala installation on Linux



Scala is an acronym for scalable language. It is an Object oriented language runs on JVM. Scala can be also used with different software’s like apache-spark etc.In this article, we will be known about the installation of scala on Centos 7.
First, Install the latest version java by using the following command.

#yum -y install java-1.8.0-openjdk

Now configure JAVA_HOMe and JRE_HOME.
Edit the file /etc/profile and add the following commands at the end of the file.

 #vi /etc/profile
 export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-
 export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-

Then run the command source /etc/profile to save changes or logout and login to save changes.

Now Download the latest version of scala from their official site

 [root@localhost ~]# wget
 --2017-01-29 01:45:36--
 Resolving (,,, ...
 Connecting to (||:80... connected.
 HTTP request sent, awaiting response... 200 OK
 Length: 131376905 (125M) [application/octet-stream]
 Saving to: ‘scala-2.12.1.rpm’

100%[============================================================================================>] 131,376,905 679KB/s in 4m 57s

2017-01-29 01:50:34 (432 KB/s) - ‘scala-2.12.1.rpm’ saved [131376905/131376905]

Install it by using the rpm command as follows

# rpm -ivh scala-2.12.1.rpm

Once the installation completes checking its version by using the following command

#scala -version


Scala code runner version 2.12.1 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.

Run the scala command to get scalashell

[root@localhost ~]# scala
Welcome to Scala 2.12.1 (OpenJDK 64-Bit Server VM, Java 1.8.0_121).
Type in expressions for evaluation. Or try :help.

scala> 3+9
res0: Int = 12
scala> 25-9
res0: Int = 16

scala> 25*9
res1: Int = 225

scala> 25/5
res2: Int = 5

scala> 25%4
res3: Int = 1

scala> println("welcome to new programming world")
welcome to new programming world

scala> :q
[root@localhost ~]#

We can quit the shell by using :q command.We can compile scala source code by using the scalac compiler.

For example, create a file with name test.scala with the following code

object test
  def main(args: Array[String])
    println("Test program executed successfully ")

Now compile and run the program as follows

[root@localhost ~]# scalac test.scala
[root@localhost ~]# scala test
Test program executed successfully
[root@localhost ~]#

we can also use scala integrate with java. Now a days many companies like twitter using the scala.