Years ago, I wrote a detailed post on getting Lisp running on Mac OS X. It remains one of my most-read posts, which is kind of cool, although that worries me a bit; a lot has changed since then, and I have no idea if it’s still the way to do it.
I have recently decided to try some things in Clojure, and I decided to set up my Surface Pro 3 with Clojure. This turned out to be a bit more difficult than I expected, actually; there’s a pretty good description at clojure-doc.org, but it didn’t work out of the box for me. You can Bing or Google for people’s setups, and that lead me closer to getting it working, but it was still pretty fiddly. Anyway, here’s what I did.
First, you need a JVM. I installed the latest Java 8 runtime from Oracle, available here. Be sure to get the 64-bit version if you’re running 64-bit Windows, as I am on my Surface. I went with Java 8 because that’s what’s required by the security policy at work; I use my Surface on the work network as well, and IT does all kinds of software scanning and the staff are prone to freak out if you’re not running the latest security-patched stuff.
Second, get Emacs. I installed 24.3, which turned out to be a mistake, as we’ll see. You should probably install 24.4, but I admit I haven’t upgraded just yet, because I’ve got a configuration that works and don’t want to break it. I put Emacs in the c:\Program Files (x86) directory, although I’ve also put it up on the root of my disk too. I also added the bin directory of the emacs install to my path, so I could run it from the command line.
If you install Emacs 24.3 as I did, the TLS software in it for Windows is broken, which causes problems later (that I didn’t realize right away). Go to Eli Zaretskii’s gnutls build from sourceforge, download and unpack gnutls, and copy all the DLLs in the zip there to the bin directory of the Emacs install. If you don’t, you won’t be able to get elpa, the new Emacs package manager, to connect to the marmalade package repository, which you’ll want to do to download the packages you need for Clojure integration. Supposedly, this isn’t a problem in 24.4, but I haven’t verified that yet. I’ll try it at some point and report back. Anyway, see the page for the Marmalade repo for details if you can’t get the elpa, package manager to download packages from the repo.
Next up, you need to customize your emacs install a bit. Fire up emacs by running run-emacs, and edit ~/.emacs.d/init.el. I’m not going to give you an emacs tutorial here; there’s lots of good stuff about emacs elsewhere, and if you’re really not sure how to use emacs you might want to get into Clojure a little more gently using a more forgiving IDE for Clojure like Nightcode, which I’ve downloaded but not tried.
I set up my init.el file to look like this:
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "http://stable.melpa.org/packages/") t)
(add-to-list 'package-archives
'("marmalade" . "https://marmalade-repo.org/packages/"))
(when (< emacs-major-version 24) (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))) (package-initialize) (package-refresh-contents) (defvar my-packages '(projectile clojure-mode cider paredit)) (dolist (p my-packages) (unless (package-installed-p p) (package-install p))) (custom-set-variables '(tool-bar-mode nil))
The magic at the beginning requires the package module to be loaded, and then sets you up with two package repositories --- melpa-stable, and marmalade. This turned out to be tricky; if you just Bing for this setup, you'll see lots of blog posts about how people have gotten it to work --- but the posts are old, and the package repository URLs have changed since they posted! So I should say --- this works for me now, and those URLs look pretty stable, but if this doesn't work for you when you're bringing up Clojure in the future, do a bit of digging around for these repos and see what the package URLs for them are.
Anyway, then we initialize the package system, and refresh the package lists. You really don't have to do this on every startup, but it doesn't take that long, so I left it there.
Next up is a list of packages: projectile, clojure-mode, cider, and paredit. I pilfered this list from what other people suggest; you can add your own. Projectile is a project management package; clojure-mode is the editing mode for clojure; cider is an interactive environment for clojure (like SLIME, which you can also get to work with Clojure, although I haven't tried seriously to do that), and finally paredit, which is a module for managing parenthesis. Anyway, with his list we walk the list and install each package if it's not already installed.
The rest of my init.el is setup boilerplate, turning off the toolbar mode. I've got other setup stuff in other config files from the past I'll probably move over at some point.
Run the buffer, or quit and restart emacs. I prefer the second path, to make sure it's going to work the next time I start emacs. It'll take a while to download and install the packages.
Next up, install Leiningen, the Clojure package manager. You can get a spiffy installer to download and run on the Leiningen site here.
Once you get this far, you should be able to pick up on the Clojure with Emacs page at the "Creating a project" section using Leiningen. Or you can launch emacs and get to a REPL by using M-x cider-jack-in to start Clojure and give you an interactive REPL. (Oh, yeah, if you follow the steps at the clojure-doc page, the version of cider you're using when I write this is 0.8.2, but check it when you set up the cider dependency in your project.)
Next up for me, learning Leiningen so I can get the dependencies I need for my project sorted out.
Happy hacking!