Scala installation on Linux

0
416

Scala

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-1.8.0.121-0.b13.el7_3.x86_64/
 export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64/jre

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 http://downloads.lightbend.com/scala/2.12.1/scala-2.12.1.rpm
 --2017-01-29 01:45:36-- http://downloads.lightbend.com/scala/2.12.1/scala-2.12.1.rpm
 Resolving downloads.lightbend.com (downloads.lightbend.com)... 54.230.190.153, 54.230.190.245, 54.230.190.28, ...
 Connecting to downloads.lightbend.com (downloads.lightbend.com)|54.230.190.153|: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

Output:

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.