If you want to install and run the latest version of Scala and/or Netbeans then you cannot simply install it from your distributions repositories or pre-built packages. It may sound easy enough to just grab Netbeans from their site and install it, but most Linux distributions no longer have Sun Java packages in their repositories.

So after a little bit of mucking about, reading manual pages and documentation I struck upon the following method of setting it all up. Fortunately it is very easy to install and I have used the following instructions to setup configure Ubuntu or Ubuntu like machines.

Installing Sun Java JDK

As I mentioned earlier most distributions no longer come with Sun Java and do not have the ability to include it in their extras/proprietary packages. This is caused by a change in the licencing of Java after Oracle bought out Sun. To compound this pain further Oracle do not produce packages for the various popular Linux variants.

Luckily a number of like minded people have set about creating custom packages for those of us that require Sun Java. On Ubuntu you can use the PPA produced by the team at webupd8.org to install Sun JDK.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

To test and ensure that your system is running the correct version of Java you can execute the following command:

java -version

The resulting output should look something like the following:

java version “1.7.0_17”

Java(TM) SE Runtime Environment (build 1.7.0_17-b02)

Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

The webup8.org team have a number of troubleshooting hints on their announcement article if you have some kind of trouble getting this PPA installed.

Installing Netbeans

Netbeans is nice and simple to install on Linux as it has a handy graphical wizard to lead you through the installation steps. I use the following commands to download and install it (7.3 is the latest version at the time of writing, but you can easily supply an releases download URL here):

cd ~
wget download.netbeans.org/netbeans/7.3/final/bundles/netbeans-7.3-linux.sh
chmod +x netbeans-7.3-linux.sh
./netbeans-7.3-linux.sh

The installation wizard will then start up after a moment and you can pretty much stick with the default options. This should mean that it will install Netbeans to a directory at /home/<user>/netbeans-7.3.

Of course if you are more comfortable with a GUI then you can simply download it from the Netbeans website in your web browser.

Installing Scala

Finally we get to Scala itself and thankfully it also has a reasonably simple set of setup instructions. You will need to download the latest release from the Scala website. Once again here are the commands I used to download and install the latest release of Scala on my machine:

wget http://www.scala-lang.org/downloads/distrib/files/scala-2.10.1.tgz
tar -xzf scala-2.10.1.tgz
sudo mv scala-2.10.1 /usr/share/scala

Now we need to tell Linux where to look when references to Scala are made so edit ~/.profile to add the following environment variables:

export SCALA_HOME=/usr/share/scala
export PATH=$PATH:$SCALA_HOME/bin

You will now need to log out and back in again for the environment setting to take effect.

As an aside and in case you did not already know; .bashrc is executed whenever a new bash session is started (such as opening a new terminal) and .profile is executed when a user logs in. Netbeans is not able to see environment variables set in .bashrc as it is run after the environment Netbeans is started in has been constructed. This is explained in more detail by a Netbeans issue report.

There is another way around this problem, but I prefer the .profile route as it universally available. However if you wish you can set a Netbeans startup configuration variable called scala.home on end of the netbeans_default_options setting in ~/netbeans-7.3/etc/netbeans.conf like so:

netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true -J-Dsun.awt.disableMixing=true -J-Dscala.home=/usr/share/scala"

Installing nbscala

Now that Netbeans is successfully installed and it can see the SCALA_HOME environment variable we can install the nbscala plugin. The simplest method is to simply install the plugin using the Netbeans plugin manager, which can be found in Tools > Plugins > Available Plugins. Install all the available Scala plugins.

If you prefer a more manual route then you can download the latest nbscala from the project on SourceForge. It is then possible to manually install the plugin using the process documented on the Netbeans wiki.

Restart Netbeans and then go File > New Project... followed by choosing Scala > Scala Application and clicking Next. After giving it a name and location click Finish to be presented with your new application. With the example Main.scala file open in your main Netbeans pane hit F6 to compile and run the code.

You should be presented with a nice compile status message and the Hello World message in your output pane at the base of the Netbeans IDE.

The installation of all the tools is now complete and you can go ahead and begin developing with Scala!