blog van Paul Hildebrand
Posts tagged linux
Installing scala 2.8.1 on Ubuntu 10.10
Dec 12th
This article is about installing scala 2.8.1 on ubuntu. Scala is also in the ubuntu repositories but then you get version 2.7.7. If you don’t mind using that version then skip the rest of the article and install using:
$ sudo apt-get install scala
It might be that you already have installed Scala on your ubuntu OS. You can remove it using the following command. (This step is not necessary).
$ sudo apt-get remove scala
Installing java development kit
In some cases Scala seems to have problems with openjdk-6 therefore we have to install the sun version of the JDK:
$ sudo apt-get install sun-java6-jdk
To make this the default java version do:
$ sudo update-java-alternatives -s java-6-sun
Make sure the right version is installed by:
$ java -version
Installing Scala
Download scala 2.8.1 from http://www.scala-lang.org/downloads and choose the unix version.
In this article Scala will be installed in /opt/scala/scala-2.8.1.final. But you can of-course choose to install it in another location. But make sure you change the paths shown here accordingly.
Open a terminal and go to the directory where you downloaded the file and do the following:
$ sudo mkdir -p /opt/scala $ sudo cp scala-2.8.1.final.tgz /opt/scala $ cd /opt/scala $ sudo tar -zxvf scala-2.8.1.final.tgz
Scala is now installed in /opt/scala/scala-2.8.1.final. We need to make to executables available on the path. Therefore we adjust the file ~/.bashrc in your home directory. Open the file with editor of choice and add at the end of the file:
export SCALA_HOME=/opt/scala/scala-2.8.1.final export PATH=$SCALA_HOME/bin:$PATH
Normally this would be the end of the installation, but I ran into some problems with the FSC (Fast Scala Compiler). If got the following exception while running scala HelloWorld.scala
Could not connect to compilation daemon. Exception in thread "main" java.lang.Exception: fsc failure at scala.tools.nsc.CompileSocket.fatal(CompileSocket.scala:50) at scala.tools.nsc.CompileSocket.getPort(CompileSocket.scala:122) at scala.tools.nsc.CompileSocket.getsock$1(CompileSocket.scala:152) at scala.tools.nsc.CompileSocket.getOrCreateSocket(CompileSocket.scala:170) at scala.tools.nsc.ScriptRunner$.compileWithDaemon(ScriptRunner.scala:145) at scala.tools.nsc.ScriptRunner$.compile$1(ScriptRunner.scala:197) at scala.tools.nsc.ScriptRunner$.withCompiledScript(ScriptRunner.scala:225) at scala.tools.nsc.ScriptRunner$.runScript(ScriptRunner.scala:265) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:91) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Normally if the FSC deamon is not started yet it should be started automatically but somehow this doesn’t work on my machine. Maybe it is to slow (Intel Atom A330) and gives a timeout before it is actually started? I can fix this by calling FSC manually first:
$ fsc Could not connect to compilation daemon. $ ps -ef | grep scala paulh 4234 1 30 15:24 pts/0 00:00:03 java -Xmx256M -Xms32M -cp /opt/scala/scala-2.8.1.final/lib/jline.jar:/opt/scala/scala-2.8.1.final/lib/scala-compiler.jar:/opt/scala/scala-2.8.1.final/lib/scala-dbc.jar:/opt/scala/scala-2.8.1.final/lib/scala-library.jar:/opt/scala/scala-2.8.1.final/lib/scala-swing.jar:/opt/scala/scala-2.8.1.final/lib/scalap.jar -Dscala.home=/opt/scala/scala-2.8.1.final -Denv.emacs= scala.tools.nsc.MainGenericRunner scala.tools.nsc.CompileServer
Although it says it could not connect to the compilation daemon, it was started anyway. Now all works like a charm.
I could add fsc to the ubuntu startup script but that isn’t a great solution to the problem, especially because Scala 2.7.7 which Ubuntu provides does not have this problem. If anyone has a better solution then please put it down this article.
Let’s hope that Ubuntu will upgrade scala in version 11.04.