Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Scala


1. Scala
Scala combines object-oriented and functional programming in one concise, high-level language. Scala's static types help avoid bugs in complex applications, and its JVM and JavaScript runtimes let you build high-performance systems with easy access to huge ecosystems of libraries. From the Scala web site at https://www.scala-lang.org/ .

2. CentOS installation
Note: Scala is built on and requires Java. See Java .

The following Linux command(s) to install Scala from the command line.
cd ~ wget http://downloads.lightbend.com/scala/2.11.8/scala-2.11-8.rpm sudo yum -y install scala-2.11-8.rpm cd ~

The following is intended to be run as a Bash script and not typed in at the command line.

The following Linux command(s) to install scala in a Bash script.
IVER1=scala-2.11-8 if [ -f /usr/bin/scala ]; then    echo -e "scala appears to be installed, nothing done" else    cd ~    if [ -f ~/$IVER1.rpm ]; then       echo -e "$IVER1.rpm exists, nothing done"    else       echo -e "$IVER1.rpm not found, getting it"       wget http://downloads.lightbend.com/scala/2.11.8/$IVER1.rpm       fi    sudo yum -y install $IVER1.rpm    fi


3. Check the installed version
The following Linux command(s) to check the installed version of Scala.
scala -version

On 2019-08-15 the output was as follows.
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL


4. Hello world in Scala
The file type of a Scala program file is scala.

The following Linux command(s) create/edit a hello program in the your home directory using the nano text editor.
nano ~/hello.scala

Create the following program text in the editor that will output the text "Hello world"
object HelloWorld {    def main(args: Array[String]): Unit = {       println("Hello world")       }    }

To exit with save, remember to press Ctrl-X, then "y" (for yes) and Enter to exit.

The following Linux command(s) run the program.
scala !/hello.scala

The output should be as follows.
Hello world

Note: Since Scala is Java-based and a somewhat sophisticated (read as complicated) system, you may need to wait a while for even a simple "Hello world" program to compile and run.

5. End of page