Here’s a quick guide on how to install Scala on linux (in my case Ubuntu 9.04). A prerequisite obviously is to have the sun jdk installed and properly integrated into your linux environment. For completeness I detail how I normally tend to set up the jdk on my linux environment before moving onto the installation of Scala. Note that here /opt/ is used as the destination directory for installation as that is what I prefer but this can be any directory that you have write permissions on. You’ll also note that I don’t use any automated linux installation tool like apt-get and that is deliberate as the following methods of installation allow you not only complete control of installation of the packages but greater flexibility when upgrading. Finally we’ll look at adding Scala support to my favourite command line editor – Vim.
Install Sun JDK
Download the latest Sun JDK (JDK 6 Update 14 at time of writing).
Make executable and extract.
$ chmod u+x jdk-6u14-linux-i586.bin $ ./jdk-6u14-linux-i586.bin
Relocate.
$ mv jdk1.6.0_14/ /opt/
Symlink.
$ cd /opt/ $ ln -s jdk1.6.0_14/ java
In /etc/profile set JAVA_HOME variable and add JDK bin directory to system path.
export JAVA_HOME="/opt/java"
export PATH="${JAVA_HOME}/bin:${PATH}"
Import your newly modified profile
$ source /etc/profile
Test Java.
$ java -version java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode) $ javac -version javac 1.6.0_14
Install Scala
Download the latest Scala (2.7.5 at time of writing).
Extract.
$ tar -xvzf scala-2.7.5.final.tgz
Move.
$ mv scala-2.7.5.final/ /opt/
Symlink.
$ cd /opt/ $ ln -s scala-2.7.5.final/ scala
In /etc/profile set SCALA_HOME environment variable and add the Scala bin directory to your system path.
export SCALA_HOME="/opt/scala"
export PATH="${SCALA_HOME}/bin:${JAVA_HOME}/bin:${PATH}"
Import your newly modified profile
$ source /etc/profile
Test Scala.
$ scala
Welcome to Scala version 2.7.5.final (Java HotSpot(TM) Server VM, Java 1.6.0_14).
Type in expressions to have them evaluated.
Type :help for more information.
scala> 1+1
res0: Int = 2
scala> println("Hello World!")
Hello World!
Add Scala support into Vim
If you’re like me and you can’t live without Vim or you just need Vim to get started with Scala prior to moving onto your favourite IDE then here’s how you can add Scala support into Vim.
Create required vim directories.
$ mkdir -pv ~/.vim/ftdetect $ mkdir -pv ~/.vim/indent $ mkdir -pv ~/.vim/syntax
Download Scala support into vim directories.
$ wget --no-check-certificate https://lampsvn.epfl.ch/trac/scala/export/18260/scala-tool-support/trunk/src/vim/ftdetect/scala.vim -O ~/.vim/ftdetect/scala.vim $ wget --no-check-certificate https://lampsvn.epfl.ch/trac/scala/export/18260/scala-tool-support/trunk/src/vim/indent/scala.vim -O ~/.vim/indent/scala.vim $ wget --no-check-certificate https://lampsvn.epfl.ch/trac/scala/export/18260/scala-tool-support/trunk/src/vim/syntax/scala.vim -O ~/.vim/syntax/scala.vim
Create a basic ~/.vimrc configuration if you haven’t got one.
set nocompatible set nu syntax on filetype indent on set autoindent set ic set hls set lbr colorscheme delek
Try editing a Scala file. It should appear in colour.
1 for {i <- 1 to 10 2 j <- 1 to 10} 3 println(i*j)
Rejoice. Get coffee. Develop. Lose sleep. The usual lifecycle.
Acknowledgements (Scala Vim support, Vim colorised output).
{ 7 comments… read them below or add one }
Thanks a lot; the vim instructions and the vimrc bit is very useful
My pleasure Alex. Thanks for stopping by.
Thanks Dhruba. Installing plugin was like piece of cake in cygwin!
Hi,
A video from YouTube on how to install Java 6 on Ubuntu here.
Sunil.
Even works for the quasi-vimgorant. After installing two highliters, yours worked right off. Thanks! I’m anxious to get into Java (for mobile development) but avoid the utter boredom of learning a language seemingly designed to protect the programmer from occasional bouts with pure creativity. Scala might be a side door to the cathedral, just off the bazaar. Near the cindered arches.
Many thanks for posting this . Very helpful tutorial.
Regards
Excellent thanks! This is working as expected on Mac OS 10.6.7
{ 1 trackback }