Scala is an “object-functional” programming language, which aims to clean up what some people consider to be poor design decisions of Java. Scala runs on the Java platform (Java Virtual Machine) and is compatible with existing Java programs. Because Scala runs on the JVM, Java and Scala classes can be freely mixed. Java libraries, frameworks and tools are all available to Scala.
Scala runs on all common JVMs and also on Android. For this tutorial, we will start by installing the Java Runtime, and then Scala. Scala 2.9.3 is the current maintenance release of Scala at the time of this article, however the steps should be the same for other versions- you will just need to download a different link with wget, and decompress that file.
SSH to your Pod as root (or use sudo), and run these commands.
Scala requires Java Runtime 1.6 or later; you can skip installing Java if you already meet this requirement (command to find out: java -version):
root@mypod:~# sudo add-apt-repository ppa:webupd8team/java root@mypod:~# sudo apt-get update root@mypod:~# sudo apt-get install oracle-java7-installer
Now that Java is installed, let’s install Scala 2.9.3 by downloading, decompressing it, and linking to its binaries:
root@mypod:~# sudo wget http://www.scala-lang.org/files/archive/scala-2.9.3.tgz root@mypod:~# sudo tar zxf scala-2.9.3.tgz root@mypod:~# sudo mv scala-2.9.3.tgz /usr/share/scala root@mypod:~# sudo ln -s /usr/share/scala/bin/scala /usr/bin/scala root@mypod:~# sudo ln -s /usr/share/scala/bin/scalac /usr/bin/scalac root@mypod:~# sudo ln -s /usr/share/scala/bin/fsc /usr/bin/fsc root@mypod:~# sudo ln -s /usr/share/scala/bin/sbaz /usr/bin/sbaz root@mypod:~# sudo ln -s /usr/share/scala/bin/sbaz-setup /usr/bin/sbaz-setup root@mypod:~# sudo ln -s /usr/share/scala/bin/scaladoc /usr/bin/scaladoc root@mypod:~# sudo ln -s /usr/share/scala/bin/scalap /usr/bin/scalap
Want to try it out? Let’s write your first Scala program. Create a file called HelloWorld.scala using your favorite text editor. It should contain this:
object HelloWorld { def main(args: Array[String]) { println("Hello, world!") } }
scalac will compile this for you, and scala will run it.
root@mypod:~# scalac HelloWorld.scala root@mypod:~# scala HelloWorld
This should display “Hello World!” to the console.
You can visit the official Scala web site to learn more about Scala.