Friday, June 10, 2011

In the beginning, there was...a bunch of freaking setup...

The assumption here is that you are completely new to programming. It also assumes you can use a computer and install basic programs. Given you are comfortable with those assumptions, you will find the following guide's format pleasing. It will both present a "wordy" description of the steps to take. And it will also be interspersed with YouTube videos you can watch to see the "wordy descriptions" in action. I will keep this general model in future posts so that if you are unable to follow along on your own PC, you can at least see what's happening by watching the videos (perhaps you are on your mobile phone or tablet device).

This post is a step-by-step guide for Windows to install all the infrastructure needed in future posts; the basic tools we will be using to do our exploring. It will cover the two Scala programming environments; REPL interactive command line (for experimenting immediately) and the Scala IDE plug-in for Eclipse (for writing, running and debugging actual programs).


Let's get started.


Note: At some point later, I may later add the step-by-step guides for Mac, Linux, IntelliJ and Netbeans. However, I am also happy to work with anyone who would like to create a "version pathway" for their particular tools.


Thousand Foot Summary

  1. Creating a Projects/Tools folder
  2. Install latest version of Java SDK from Oracle/Sun (1.6.0_25 or later) into Projects/Tools/Oracle/Java
  3. Install latest version of Scala Stack from TypeSafe (2.9.0 or later) into Projects/Tools/TypeSafe/Scala
  4. Install latest version of Eclipse (3.6.2 or later) in Projects/Tools/Eclipse
    1. Install latest version of Scala IDE for Eclipse (2.0.0 or later)
  5. There are a series of dependencies in the above folder layout. The root dependency for all of the installed tools is the Java SDK. It is used by all of these different tools we are installing. Scala depends upon the Java platform (although, it can also use the .NET platform, too).

Okay, now for the on-the-ground details.

Creating a Projects/Tools Folder

The purpose of this step is to make life easier for us as we move through the intricate dance of making all these tools and their interdependencies work. For example, there are some older Java libraries that will barf if you supply a folder path containing a space (which "Program Files" conveniently has right in its center).

When I am setting up a new computer, I always create two partitions. The first, assigned to C: and made bootable, is the OS partition. I make sure there is plenty of space for future OS patches, driver installs and miscellaneous OS growth issues. And the second, assigned to D:, is the non-OS partition. It takes up the remaining room on the underlying hard drive. And it is into this particular place I install all my applications (just replacing C: with D: and leaving the rest of the default path defaults alone). By doing this, I make doing OS re-installs and OS upgrades much more palatable.

Another option is to plug in a USB drive and use it. It may have a drive letter of E:, F: or any other "letter" followed by a colon. As long as the drive is read/write, you are good to go.

So, create a folder called Projects at the root of your application drive (D: in my personal example above). And inside of the Projects folder, create a Tools sub-folder. Again, it's very important that the Projects folder be at the root of whatever partition you choose.

Next, we are going to create three sub-folders in the Tools folder; Eclipse, Oracle and Typesafe. And in the Oracle folder, we are going create a Java folder. And we're done with the initial set-up. Watch this video to ensure you got everything named correctly:



It's VERY important you don't add spaces and keep the upper/lower case of the names the same (don't make everything lower case - that can cause you issues later that take hours to figure out, especially if we end up heading towards Linux at some point).

Installing the Java SDK (aka JDK)

Download the Java SDK (currently at this direct link). You need to ensure you are getting Java 1.6.0_25 or higher. Once the download has completed, double click on the .exe to have it begin installing. Once the installation has begun, you will eventually arrive at a dialog which will likely provide a default installation location of "C:\Program Files\Java\jdk1.6.0_25" (with the version suffix possibly different if you are dl'ing a later version). In the text at the bottom, change it to read "D:\Projects\Tools\Oracle\Java\jdk1.6.0_25" (no trailing back slash). Once you click "Okay", the screen should appear similar to this:

Click "Next >" and the installer should go do the work dropping the Java SDK into the proper place creating all the necessary sub-folders for you. Be certain you have both the spelling and casing correct as we will be reusing this particular pathway in other installers, later. Additionally, if a second dialog comes up (installing the JRE, be sure to update it's installation path with the appropriate drive letter but keep everything after the drive letter including the "Program Files" part. Once that completes, we have the proper version of Java set-up.

Here's the video details for installing Java:

Java installation complete!

Installing the Scala SDK (aka Typesafe-Stack)

Now it is time to install Scala itself. Download the Scala Stack SDK (currently as this direct link). You need to ensure you are getting Scala Stack 2.9.0 or higher. Once the download has completed, extract the resulting .zip file to "D:\Projects\Tools\TypeSafe\Scala\scala-2.9.0.1".

To validate the install, bring up an instance of the command prompt (Start/Accessories/Command Prompt). Then, enter the drive where you put the "Projects/Tools" folder and select return. In my case, I would type "D:". Then enter "cd D:\Projects\Tools\TypeSafe\Scala\scala-2.9.0.1\bin" and press return. It will take a minute or two for Scala REPL to start up. Once it starts, it will show the version of Java it has found and is now using. This version of Java needs to be the same as the one you installed in the Java SDK steps above.

Here's the video for these steps:

Congratulations! You now have the Scala core installed. We still have a ways to go to get you writing code in an IDE and using it.

Installing the Eclipse IDE

Download the Eclipse IDE (currently as this direct link). You need to ensure you are getting Eclipse 3.6.2 or higher. Once the download has completed, extract the resulting .zip file to "D:\Projects\Tools\Eclipse\eclipse-java-helios-SR2-win32-x86_64".


To validate the install, bring up an instance of the File Explorer. And then navigate to "D:\Projects\Tools\Eclipse\eclipse-java-helios-SR2-win32-x86_64". In that folder, double click on the eclipse.exe file which will bring up the Eclipse IDE. It will take a minute or two for it to start up.

Close the Eclipse IDE. We must make a few changes to how it starts to accommodate the Scala IDE. First, right mouse button on the eclipse.exe icon and drag to the desktop. When given the option, select "Create Shortcut". This will make an eclipse shortcut appear on your desktop. Right mouse on this new desktop shortcut and select "Properties". In the "Target:" text field, replace whatever is there with "D:\Projects\Tools\Eclipse\eclipse-java-helios-SR2-win32-x86_64\eclipse\eclipse.exe -vm "D:\Projects\Tools\Oracle\Java\jdk1.6.0_25\bin\javaw.exe" -vmargs -Xmx2048M" (all the yellow text including the yellow double-quotes must be copied and pasted) and select "Ok". Now, start the Eclipse IDE from the desktop shortcut again. It will ask for a path to a workspace. Replace whatever appears there with "D:\Projects\ProjectEuler". This will set up our default workspace for the set of ProjectEuler problems we will be working.

Congratulations! You now have a Java IDE set up. We still have one more step to get the Scala IDE up within Eclipse.

Installing the Scala IDE for Eclipse