Okay, so now that you are excited about all of the different software engineering concepts that you can learn with Scala, the first thing you will need to do is install… Java. Wait, what? It may seem a bit misleading, but the Java Development Kit (JDK) is required for Scala since the Scala programming language is built off of the Java Virtual Machine (JVM). So, you will need to ensure that it is installed as a dependency before installing Scala.
Installing Java JDK
Command to check if the Java JDK is installed on your system
If you receive an error, then you don’t have the JDK installed, and you will need to install it before moving on to installing Scala. If you do have it installed, you can skip ahead to the installing Scala section. The steps to install Java vary slightly by operating system.
Installing JDK on Windows
If you are running a Windows operating system, you will need to navigate to the following Oracle web site to download and install the most recent JDK for Windows and run through the installer wizard.
www.oracle.com/technetwork/java/javase/downloads/index.html
There should be a button that says “Download” with a reference to either the Oracle JDK or the Java Platform JDK (both will take you to the same page). From there, you will see a list of different operating systems for which you can download the JDK. Choose the download for Windows. Once the download is complete, you can open up the installer executable file and walk through the wizard. You should be able to choose all of the default installation configurations (unless you feel strongly otherwise).
You can verify that the installation worked correctly by clicking your start menu and search for cmd to open up a command-line terminal. From there, type in javac -version as you did at the beginning of this chapter. If a version number is returned, the installation worked correctly. If you encounter an error, then the installation did not work correctly and you will need to retrace your steps to ensure that you did not miss anything.
Installing JDK on MacOS
Terminal command to install the Homebrew package manager
Check that Homebrew was installed successfully
Install the Java JDK using Homebrew
You can verify that the installation worked correctly by typing in javac -version as you did at the beginning of this chapter. If a version number is returned, the installation worked correctly. If you encounter an error, then the installation did not work correctly and you will need to retrace your steps to ensure that you did not miss anything.
Installing JDK on Linux
For Linux-based operating systems (like Ubuntu or Debian), you can install Java through the built-in package manager apt-get. This package manager is very similar to Homebrew if you read through the section for MacOS-based systems. Most development-based packages that you might need to install as a software engineer can be managed through apt-get on a Linux machine, so it is a useful tool to be aware of.
Commands to install JDK on Linux
You can verify that the installation worked correctly by typing in javac -version as you did at the beginning of this chapter. If a version number is returned, the installation worked correctly. If you encounter an error, then the installation did not work correctly and you will need to retrace your steps to ensure that you did not miss anything.
Installing Scala
Check if Scala is installed
If the command returns a version number, then you already have Scala installed. We will be using version 2.12, the latest stable version of Scala, for the examples in this book. If you already have Scala installed, you can skip ahead to the next chapter. Conversely, if you received an error from the command in Listing 2-6, you will need to install Scala. As usual the steps vary slightly depending on what operating system you are using.
Installing Scala on Windows
To install Scala on Windows, you will need to navigate to the following Scala language web site and download the package binaries.
You will notice at first that the web site will direct you to install Scala by downloading an IDE (Integrated Development Environment) or by downloading SBT (Simple Build Tool). Those topics will be covered later in this book, but for now we do not want to install them.
Instead, navigate to the bottom of the page where there are several binary packages available to download for all operating systems under the “Other Resources” section. Pick the download that matches your version of Windows. At the time of this writing, the appropriate link will be titled “scala-2.12.7.msi” which will download a .msi installer package that you can open up to walk through a wizard installation. You should be able to select all the defaults as you walk through the wizard. When it is done installing, verify that the installation was successful by repeating the command in Listing 2-6. If you receive a version number, then you have successfully installed Scala and you are ready to get programming.
Installing Scala on MacOS
Command to install Scala on Mac
This will run through a series of installation steps including updating Homebrew for any new package references and downloading the latest version of the Scala install package. From there, it will automatically install Scala on your machine. When it is done installing, verify that the installation was successful by repeating the command in Listing 2-6. If you receive a version number, then you have successfully installed Scala and you are ready to get programming.
Installing Scala on Linux
Command to install Scala on Linux
You may also be asked to confirm the use of disk space on your computer. Type Y and hit Enter to confirm. This will download the most recent version of Scala and automatically install it on your machine. When it is done installing, verify that the installation was successful by repeating the command in Listing 2-6. If you receive a version number, then you have successfully installed Scala and you are ready to get programming.
Summary
In this chapter, you successfully installed both the Java JDK and Scala. You learned that the Java JDK is a prerequisite for Scala since the Scala programming language is built off of the JVM. You will learn more about that in the coming chapters. Additionally, if you are using either a Mac or Linux operating system, you learned about package managers and how simple and convenient they can be. You will likely use package managers a great deal throughout your career as a software engineer.
In the next chapter, you will be introduced to some prerequisite knowledge that will be extremely important context to build before you actually start programming. First, you will be introduced to command-line-based operating systems followed by a brief introduction to the linguistic concepts of syntax and semantics.