© Jason Lee Hodges 2019
J. L. HodgesSoftware Engineering from Scratchhttps://doi.org/10.1007/978-1-4842-5206-2_2

2. Installing Everything You Need

Jason Lee Hodges1 
(1)
Draper, UT, USA
 

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

As of the time of this writing, you will need to ensure that you have the Java Development Kit or JDK version 1.8 or higher. You can check to see if you already have it installed by opening up a command line (in Windows cmd.exe or in macOS or Linux open up a terminal). From there, type the code listed on the first line in Listing 2-1, which will return to you on the second line the version of Java you have installed.
> javac -version
javac1.8.0_171
Listing 2-1

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

If you are on a MacOS system, the easiest way to install the JDK is using Homebrew, which is a command-line package installer. You can visit https://brew.sh for simple installation instructions. At the time of this writing, the installation instructions for Homebrew are simply to open up a terminal (you can hit command + space bar and search for “terminal”) and type in the command shown in Listing 2-2.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Listing 2-2

Terminal command to install the Homebrew package manager

This command will prompt you to hit Enter/Return in order to confirm that it will install a number of directories on your computer. It will then ask you for your system password. Once that has been entered, it will automatically install everything you need to use the Homebrew package manager. This package manager can install most programs that you will need for development purposes on a Mac so it is a useful thing to have as a software engineer. You can browse some of the packages you can install with Homebrew by navigating to https://formulae.brew.sh . Verify that you have Homebrew installed correctly by typing in the command in Listing 2-3. If a version number is returned, then it was successfully installed.
>brew --version
Homebrew 1.8.3
Listing 2-3

Check that Homebrew was installed successfully

Once Homebrew is installed, all you need to do to install the JDK is type the two commands in Listing 2-4. The first command will update all the packages that Homebrew has a reference to on your computer. The second command actually does the installation.
> brew update
> brew cask install java
Listing 2-4

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.

To install the Java JDK on Linux, simply open a terminal (click your Home button and search for terminal) and type in the commands in Listing 2-5. The first command will update the package manager to ensure you have the latest package references. The second command actually does the installation. The first word, sudo, stands for “Super User Do” and allows you administrator rights to the command that is about to be executed. It will prompt you for your administrator password.
> sudo apt-get update
> sudo apt-get install default-jdk
Listing 2-5

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

Once you have the Java JDK installed on your computer, you can move on to installing Scala which is the programming language that we will be using to demonstrate the various software engineering paradigms in this book. You can check if it is already installed by typing the command in Listing 2-6 into a command prompt or terminal.
> scala -version
Scala code runner version 2.12.7 – Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc.
Listing 2-6

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.

www.scala-lang.org/download/

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

To install Scala on a Mac, you can use the same package installer that you used to install Java, Homebrew. If you already had Java installed and did not need to install the Homebrew package manager, go back to the section in this chapter that covered installing Java for Mac and follow the instructions to install Homebrew. Once you have confirmed that Homebrew is installed on your Mac, you can run the command in Listing 2-7 to install Scala.
> brew install [email protected]
Listing 2-7

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

To install Scala on the Linux operating system, you can use the same package manager you used to install Java. Use the commands in Listing 2-8 to install Scala on your machine. You will be prompted for your machine’s administrator password due to the use of the sudo command.
> sudo wget https://downloads.lightbend.com/scala/2.12.7/scala-2.12.7.deb
> sudo dpkg -i scala-2.12.7.deb
> sudo apt-get update
> sudo apt-get install scala
Listing 2-8

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.34.62