Added on 9 September 2019

This post was originally published as "Installing Lisp on a Mac". It turns out that post was largely applicable for both Mac and Linux environments.

Updates have been made to include Linux-specific instructions regarding the installation of Emacs and SBCL, but the contents remain largely unchanged.

On a complete whim I felt the urge to look into the Lisp programming language. Installation isn't as straightforward as I expected so I have written a small guide outlining the steps I took to get set up.

Lisp overview

Unlike most programming languages, there are no universal implementations of Lisp. Lisp is better known as a family of programming languages. This means there are many different "flavours" of Lisp (called dialects) that each bring their own programming styles to the table.

Two popular versions of Lisp are Common Lisp and Scheme. At a first glance the differences between the two are barely noticeable. The differences lie in what features the dialect has and what tools are available to customise the language. The ability to be customised is what makes Lisp stand out.

The free, online version of the Practical Common Lisp book provides a very good introduction to Lips and the components required to get Lisp up and running.

My development environment

Here is what I used when setting up my development environment:

As a rule of thumb, all Lisp development, regardless of the environment, will require:

Emacs is generally the preferred editor for writing Lisp due to the SLIME plugin, which turns Emacs into a fully-fledged Lisp development environment.

Setting up Lisp

Install/update Emacs

macOS

Most Mac computers come with Emacs 22 installed but to use the package manager for Emacs, version 24 or higher is required. For macOS, an updated instance of Emacs can be installed with Homebrew using the brew install emacs command.

As a general rule, to make sure the Homebrew version of applications such as Emacs are loaded instead of the system default, ensure that /usr/local/bin comes before /usr/bin in the $PATH variable.

Linux

There are several ways to install Emacs:

  1. by installing a Personal Package Archive (PPA);
  2. by installing via a software manager (e.g. Snapcraft); or
  3. by compiling from source.

I opted to install via Snapcraft (using the GNU Emacs snap published by Alex Murray) as my instance of Linux Mint came with Snapcraft ready to go.

Install the SBCL compiler

Common Lisp is one of the more straight forward compilers to use when starting out. The SBCL compiler can be used to compile all Lisp code as Common Lisp.

macOS

This can also be installed with Homebrew by running brew install sbcl.

Linux

SBCL will need to be installed from the source on Linux. To do this:

  1. download the appropriate binary for the required platform from the SBCL "Downloads" page (I used the Linux AMD64 1.5.6 binary at the time of writing); and
  2. follow the "Installing a binary" instructions on the SBCL page.

For reference, the installation instructions on the site at the time of writing are:

$ bzip2 -cd sbcl-1.5.6-x86-linux-binary.tar.bz2 | tar xvf -
$ cd sbcl-1.5.6-x86-linux
$ sh install.sh

Set up MELPA

The package manager in Emacs is called MELPA. Installing MELPA makes installing the remaining required components much simpler.

Create an init.el file under ~/.emacs.d/ and follow the instructions on the MELPA website to install MELPA.

Install SLIME

With MELPA set up the SLIME package can be installed. Load Emacs and run the command runner by typing M-x.1

Depending on the operating system, the combination M-x may not be possible. A key such as Alt or Option will need to be reassigned to act as a Meta key instead. This will depend on the functionality of the command line interface or operating system.

After typing M-x a prompt will display at the bottom. Type package-install and press Enter, followed by slime, followed by Enter again.1

This will look like:

M-x package-install <Enter> slime <Enter>

SLIME will now begin installing. Emacs will have to restarted before SLIME can run; do this by closing Emacs with C-x + C-c and opening it again.

Run SLIME

With SLIME installed and Emacs restarted, SLIME can be run by running M-x slime.

A new window will open; congratulations, Lisp is installed and ready to compile.


Footnotes


  1. In Emacs, (and other languages) M refers to the Meta key, which is typically the Alt or Option key.

  2. Enter is sometimes written as RET, such as in the install guide for SLIME.