Skip to content

Instantly share code, notes, and snippets.

@mslinn
Last active August 29, 2015 14:08
Show Gist options
  • Save mslinn/e6de5630226f93311121 to your computer and use it in GitHub Desktop.
Save mslinn/e6de5630226f93311121 to your computer and use it in GitHub Desktop.
Installs Scala on Mac, Ubuntu and other Debian derivatives
#!/bin/bash
# Installs specified Scala version, and enables colorized REPL
SCALA_VERSION=2.11.4
if [ "$1" ]; then SCALA_VERSION=$1; fi
set -e
case "$OSTYPE" in
darwin*)
OS=Darwin
FILE=scala-$SCALA_VERSION.tgz
URL="http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz"
;;
linux*)
OS=Linux
FILE=scala-$SCALA_VERSION.deb
URL="http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.deb"
;;
*)
echo "Cannot install to $OSTYPE"
exit 2
;;
esac
if [ `curl --output /dev/null --silent --head --fail "$URL"` ]; then
echo "Error: invalid url: $URL"
exit 1
else
if [ ! -f "$FILE" ]; then
echo "Installing from $URL; temporarily saving to $FILE"
wget -O $FILE "$URL"
else
echo "$FILE already exists so installing that file instead of redownloading"
fi
fi
if [ $OS == Linux ]; then
sudo dpkg -i $FILE
echo "alias scala='scala -Dscala.color=true'" >> ~/.profile
elif [ $OS == Darwin ]; then
tar -xzf $FILE
sudo mv scala-$SCALA_VERSION /Applications/
echo "export SCALA_HOME=/Applications/scala-$SCALA_VERSION" >> ~/.bash_profile
echo "export PATH=$SCALA_HOME/bin:$PATH" >> ~/.bash_profile
echo "alias scala='scala -Dscala.color=true'" >> ~/.bash_profile
echo "To use $SCALA_VERSION, open a new console or type source ~/.bash_profile"
fi
rm $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment