Home Computer Science Building Applications with Scala
Installing Java 8 and Scala 2.11
Scala requires JVM to work, so we need get the JDK 8 before installing Scala. Go to the Oracle website, and download and install JDK 8 from http ://www. oracle. com/technetwo rk/pt/j ava/j avase/downloads/index.html.
Once you've downloaded Java, we need to add Java to the path variable; otherwise, you can use the terminal. We do this as follows:
$ cd ~/
$ wget —no-cookies —no-check-certificate —header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup- cookie"
$ tar -xzvf $ jdk-8u77-linux-x64.tar.gz $ rm -f jdk-8u77-linux-x64.tar.gz
The next step is to create the environment variable called java_home, and to put the Java 8 binaries in the PATH variable. In Linux, we need to edit the ~/.bashrc file, and export the variables we need, like in the following:
export JAVA_HOME=~/jdk1.8.0_77 export PATH=$PATH:$JAVA_HOME/bin
Save the file, and then on the same terminal we need to source the file via $ source ~/.bashrc
Now we can test our Java 8 installation. Just type in $ java -version. You should see something like the following:
$ java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) Server VM (build 25.77-b03, mixed mode)
Let's get started. We will be using the latest Scala version 2.11.8. However, the code inside this book should work with any Scala 2.11.x version. First of all, let's download Scala from h
Scala works on Windows, Mac, and Linux. For this book, I will show how to use Scala on Ubuntu Linux(Debian-based). Open your browser and go to http ://www. scaia-iang .org /download/.
Download scala 2.11.8: it will be a TGZ file. Extract it and add it to your path; otherwise, you can use the terminal. Do this as follows:
$ cd ~/
$ wget http://downloads.lightbend.eom/scala/2.11.8/scala-2.11.8.tgz $ tar -xzvf scala-2.11.8.tgz $ rm -rf scala-2.11.8.tgz
The next step is to create the environment variable called scala_home, and to put the Scala binaries in the PATH variable. In Linux, we need to edit the ~/.bashrc file and export the variables we need, like in the following:
export SCALA_HOME=~/scala-2.11.8/ export PATH=$PATH:$SCALA_HOME/bin
Save the file, and then, on the same terminal, we need to source the file via $ source ~/.bashrc.
Now we can test our Scala installation. Just type in $ scala -version. You should see something like the following:
$ scala -version
Scala code runner version 2.11.8 — Copyright 2002-2016, LAMP/EPFL
You have successfully installed Java 8 and Scala 2.11. Now we are ready to start learning the FP principles in Scala. For this, we will be using the Scala REPL in the beginning. Scala REPL is bundled with the default Scala installation, and you just need to type $ scala in your terminal as follows:
Welcome to Scala 2.11.8 (Java HotSpot(TM) Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help. scala>
Congratulations! You have installed Java 8 and Scala 2.11 successfully.
|< Prev||CONTENTS||Next >|