Installing a Clojure development environment on Ubuntu

After a not-terribly-thrilling experience upgrading to Ubuntu 11.10 (Oneiric Ocelot) on my laptop, I’ve decided to leave my desktop running Lucid Lynx for a while longer. However, I’d like to do some Clojure development on a nice, big screen, so I needed to figure out how to get a dev environment set up. It looks like this may be easier in later versions of Ubuntu, but here’s the cleanest way I could find to set it up under Lucid.

First, here’s what you’ll need to do as root to get packages installed system-wide:

  1. Install Clojure: apt-get install clojure
  2. Install SLIME.

    If you’re new to Lisp, SLIME is a very powerful Emacs mode for developing Lisp programs. It’s in the APT repositories as well: apt-get install slime

Users will also likely want to be able to easily install clojure-mode, which adds some formatting features and, more importantly, functions for communicating with Clojure processes. To do this, we’ll need to add some package management features to Emacs.

  1. Install package.el.

    Emacs 24 comes with a package management system, package.el, but, sadly, Lucid is only up to Emacs 23. However, there is a version of package.el for Emacs 23 available at, which you should download and place into /usr/local/share/emacs/23.1/site-lisp.

  2. Set up the Marmalade repository.

    The default repository used by package.el, ELPA, does not have an up-to-date version of clojure-mode. We want to add the Marmalade repository. To do this for Emacs 23, we will add the following to /etc/emacs23/site-start.el (create it if it does not exist):

    (require 'package)
    (add-to-list 'package-archives
                 '("marmalade" . ""))

Finally, we will want to install Leiningen, which, as the README states, is a tool “for automating Clojure projects without setting your hair on fire.” This is very straightforward:

  • Download the zipball for leiningen, and copy bin/lein into /usr/local/bin

That’s all we need to do as root. For each user to set up his instance of Emacs to use clojure-mode, they’ll need to do the following within Emacs:

  1. Update the package list.

    M-x package-refresh-contents

  2. List the available packages

    M-x package-list-packages

  3. Mark clojure-mode for installation.

    Scroll down to clojure-mode and hit ‘i’.

  4. Install the package.

    Hit ‘x’ to execute the installer.

Finally, you’ll want to set up the lein-swank plugin for Leiningen that lets SLIME and clojure-mode talk to Clojure processes.

  1. Bootstrap Leiningen.

    Run lein at your prompt to bootstrap Leiningen, if you haven’t already.

  2. Add the lein-swank plugin to the :user profile.

    Create a ~/.lein/profiles.clj file with the following contents:

    {:user {:plugins [ [lein-swank "1.4.4"] ]}}

At this point, you should be good to go. To test your installation:

  1. Create a test “hello” project.

    At your prompt: lein new hello

  2. Change into the new project directory.

    At your prompt: cd hello

  3. Start emacs.
  4. Try to jack in.

    In Emacs: M-x clojure-jack-in

After a moment, you should have a REPL in a new Emacs buffer!

Update: after setting this up on my laptop, which is running 11.10 (Oneiric Ocelot) and looking at the package list for Precise Pangolin, I’m pretty sure that this guide is still valid. While there is a packaged version of Leiningen, it’s older and doesn’t seem to want to play nicely with the current version of clojure-mode.

Leave a Reply