Bookmark and Share

Setting up Clojure & Emacs in Ubuntu

As I’m continuing my previous adventures with Clojure, I’m also starting to appreciate more hackerish tools. Previously I was using Enclojure plugin in NetBeans, and it definitely made the initial learning curve gentler, but here’s how to set up the environment using GNU Emacs with clojure-mode, SLIME and swank-clojure in Ubuntu. All those weird names—I’m not even sure what each of them exactly does, but together they formulate a fabulous interactive development environment. Setting them up is surprisingly easy, once you figure out what you actually need to do ;-)

Both Emacs and Java (required by Clojure) come in different flavors. While others may work, it seems that GNU’s Emacs 23 and Sun’s Java 6 are a good fit. Additionally you need Git and Ant:

~$ aptitude install sun-java6-jdk sun-java6-jre git-core ant

I’m still using Ubuntu 9.04, and its repositories seem to officially contain only Emacs 22. However, several sources strongly recommend version 23 as way more trouble-free, and it can be obtained by installing the “snapshot” package. I had luck with emacs-snapshot-gtk:

~$ aptitude install emacs-snapshot-gtk

At this point you may want to check out some quick Emacs tutorials (Google…) to get a grasp of the very basic commands and what notation like C-x b, C-x C-f and M-x means. Hint: C is the Ctrl key, M is the Alt key.

Then, get Emacs Starter Kit, which sets sane defaults and some essential libraries to the environment. In your home directory, get them straight into ~/.emacs.d/, which is where Emacs reads its configuration from:

~$ git clone git:// .emacs.d

Starting Emacs now does some compiling stuff which may show some warnings. This is normal. Then, the magic:

  1. M-x package-list-packages.
  2. Select swank-clojure (put an i beside it).
  3. Hit x to install. Emacs downloads and compiles and complains something again.
  4. M-x slime, and say y when it asks to install Clojure.

Wait for a while, and there you are!

; SLIME 20091016
user> (+ 1 2)

Here’s what’s where:

  • ~/.emacs.d/ — Emacs’s settings and libraries.
  • ~/.swank-clojure/ — Clojure, Contrib and Swank-Clojure.

Note that above we actually set up ~/.emacs.d/ as a Git repository, so updating the Emacs Starter Package is just a matter of typing

~$ cd ~/.emacs.d/
~$ git pull

To customize your own settings, create a file ~/.emacs.d/yourusername.el. Emacs will automatically load this when started.


Several new Clojure books are starting to appear way after Stuart Halloway’s world premiere Programming Clojure. The following ones are available as Alpha / Early Access previews:

As ultimate Clojure-enthusiast toys, have a look at Zazzle’s Clojure Products. But before supporting commercial parties, please consider donating Rich some money for making all this possible!

Last modified: 2010-01-17 17:55 +0200

blog comments powered by Disqus