May 20, 2008

Adventures in Scala: Part I

I am attempting to learn at least one new language a year and one of them this year is Scala. It is a multi-paradigm language that pretty much just takes Java and modernizes it. By that I mean it adds functional-style ways of doing things, like lambda statements, type inferencing, and gives it a much prettier syntax.

This article is about how to install Scala on Ubuntu. First off, you need Java installed. Scala programs compile to Java bytecode, which means you need the Java virtual machine in order to run your Scala programs. My advice is to install the sun-java6-jdk package. There are open-source Java implementations, but they suck. The Sun one is much better (the fact that it actually works is my main reason for using it).

Now the next step you might think is to then install the scala package from the Ubuntu repositories. Unfortunately as of today, that version is 2.3, and the most up-to-date one from the Scala pages is 2.7 (UPDATE Dec. 20/09: The version in the repo is 2.7.5 now, which is still not the latest version). You're much better off just doing this:
tar -zxvf
sudo mv /usr/share/scala
sudo ln -s /usr/share/scala/bin/scala /usr/bin/scala
sudo ln -s /usr/share/scala/bin/scalac /usr/bin/scalac
Now you have a working Scala implementation! Make sure to check the most up-to-date version on their website. I'll try and keep this up-to-date, but I'm only human and only check the Scala website every now and then.

To uninstall:
sudo rm -rf /usr/share/scala /usr/bin/scala /usr/bin/scalac


Anonymous said...

mkdir -p /usr/share/vim/addons/ftdetect
mkdir -p /usr/share/vim/addons/indent
mkdir -p /usr/share/vim/addons/syntax
wget --no-check-certificate -O /usr/share/vim/addons/ftdetect/scala.vim
wget --no-check-certificate -O /usr/share/vim/addons/indent/scala.vim
wget --no-check-certificate -O /usr/share/vim/addons/syntax/scala.vim

Anonymous said...

mkdir -p /usr/share/vim/vimcurrent/ftdetect
mkdir -p /usr/share/vim/vimcurrent/indent
mkdir -p /usr/share/vim/vimcurrent/syntax
wget --no-check-certificate -O /usr/share/vim/vimcurrent/ftdetect/scala.vim
wget --no-check-certificate -O /usr/share/vim/vimcurrent/indent/scala.vim
wget --no-check-certificate -O /usr/share/vim/vimcurrent/syntax/scala.vim

IllegalCharacter said...

Thank you Anonymous (whoever you are!).

The three links that you can see here are the filetype detection (ftdetect), indentation settings and syntax highlighting details for programming Scala in Vim. Always handy!

You'll need to run this stuff as root, or use sudo to do it. I wonder if there is a way to do it for an individual user?

Anonymous said...

For an individual user, use ~/.vim/ instead of /usr/share/vim/vimcurrent.

Bernard said...

Much Obliged Friend!
Worked without a single hitch.

Gabriel said...

You can now install Scala from the Ubuntu Repo:
sudo apt-get install scala

Bernard said...

Tried it. Works.
Obliged again.

Rob Britton said...

Gabriel: Yes, you've been able to get it from the Ubuntu repos for a long time now, however it is rarely the up-to-date version. Right now they've updated it to 2.7.5 and the latest version is 2.7.7 so it isn't that far apart, but they haven't been too quick to update.
I'm not exactly the fastest updater for this either, but I'm just saying that if you want the latest and greatest, go with the Scala site - although for any package, they aren't usually up to date in the repos.

Bernard: No problem!

RGauvain said...

Thank you for the excellent post. As a small addition I found it useful to include:
sudo ln -s /usr/share/scala/bin/fsc /usr/bin/fsc

This provides easy access to the scala fast compiler.

To uninstall becomes:

sudo rm -rf /usr/share/scala /usr/bin/scala /usr/bin/scalac /usr/bin/sfc