Scala Language Installation in Mac OS X


This second chapter of our series:

Install Lift 2.5 in Mac OS X

In this second chapter, we are going to install the latest and compatible version of Scala programming language. Once the Scala Language has been download it, it is necessary to proceed to its installation.
2) Install the Scala Language:

I open the finder and choose the option Go to Folder select /usr/local/, then we rename the folder to Scala and we copied the folder there.We could also move it by Terminal using the following command:

$ sudo mv ~/Downloads/scala-2.10.0.final /usr/local/share/
$ sudo mv ~/Downloads/scala /usr/local/share/

There are two possible options for making SCALA command available from the Terminal Application.

a) Modify the Home Profile file (~/.profile)
if we have already changed its file name.We edit the local PATH file. We open the Terminal application, we edit the .profile file (we can use vim editor or the TextEdit, or directly use Textmate if we have it installed using the mate ~/.profile).

open -a TextEdit .profile
SCALA_HOME=/usr/local/share/scala;
export $SCALA_HOME; export SCALA="$SCALA_HOME/bin/scala"
PATH=$SCALA_HOME/bin:$PATH; export PATH
source ~/.profile

b) To create a system link with the executable files: This makes unnecessary to modify the PATH.
We have created a Bash script to download, install and configure the symlinks:

#!/bin/sh
####################################################################
# Scala Install Script to Download and install Scala
# 
####################################################################
 
# Check the version to install
echo "Enter scala version or hit enter for 2.10.2"
read version
if [ "$version" == "" ] 
then
  version="2.10.2"
fi
 
# SETUP VARIABLES 
BIN_DIR="$HOME/bin"
# Scala File Name from Version
SCALA_VERSION_FILE="scala-$version.tgz"
SCALA_DOCS_FILE = "scala-docs-$version.txz"
 
# Scala File Name without Version
SCALA_FILE= "scala.tgz"
SCALA_COMPL_FILE= "scala"
SCALA_WEB_SITE = "http://www.scala-lang.org/files/archive"
SCALA_DOWN_URL="$SCALA_WEB_SITE/$SCALA_VERSION_FILE"
 
printf "$SCALA_DOWN_URL"
 
printf "$exec_url"
docs_url="$url/$docs"
compl_url="$url/$compl_file"
 
sudo curl "$SCALA_DOWN_URL" -o ~/Downloads/"$SCALA_FILE"
tar -xzf "$SCALA_FILE"
cd scala
echo scala-"$version".final
mv scala-"$version".final /usr/local/share/scala
 
# Scala version 
ln -s /usr/local/share/scala/bin/scala /usr/local/bin
ln -s /usr/local/share/scala/bin/scalac /usr/local/bin
ln -s /usr/local/share/scala/bin/scalap /usr/local/bin
ln -s /usr/local/share/scala/bin/scaladoc /usr/local/bin
ln -s /usr/local/share/scala/bin/fsc /usr/local/bin
ln -s /usr/local/share/scala/bin/sbaz /usr/local/bin
ln -s /usr/local/share/scala/bin/sbaz-setup /usr/local/bin

Once you have saved the file in your home directory, type ‘chmod a+x scala_setup.sh’ in Terminal to make it executable. Finally, run it with ‘./scala_setup.sh

Personally, I do prefer the last option since it is more elegant and cleaner and also since it more unlikely to have issues. Either ways, once we have finished to test it we can insert the following command on the Terminal application.

scala -version

And the following sentence will appear:

Scala code runner version 2.10.0.final -- Copyright 2002-2010, LAMP/EPFL