clj on Homebrew

Installing Homebrew

Homebrew is a helpful and growing repository of developer-centric tools. Originally it was Mac-focused but is now available for Linux and Windows WSL as well.

Installing clj from Homebrew

Once you have Homebrew installed, the Clojure formula is included in the default repository so you install by doing:

$ brew install clojure

You should see Homebrew updating its formula cache, downloading the Clojure tools, and installing them. If everything worked, try:

$ clj -e '(+ 1 1)'

The Clojure tools include support for downloading and caching libraries (including Clojure itself) using Maven (a Java package manager). If this is your first time using Clojure, you may see some additional messages above about downloading Clojure and some dependencies.

Upgrade clj to the latest version

Homebrew uses the term "update" to mean updating Homebrew itself (something that is typically done automatically for you) and "upgrade" to mean updating a Homebrew tool to the latest version of its formula.

If you’d like to update your Clojure tools version, do:

$ brew upgrade clojure

You’ll either see a warning that you already have the latest version, or brew will download and install the new version.

Downgrade to an older version

Sometimes, you will still have an old version installed, but not linked. To check, do:

$ brew list --versions clojure

If the version you want is there, you can do:

$ brew switch clojure x.y.z.r

In the more likely case that the older version is not already installed, you can find a list of older versions in the changelog.

In this process, you will create your own "tap" (formula repository) and extract an older named version from the Homebrew core repository. You can then install the older version with that named version from your own local tap.

First, create the tap, substituting your own github id into the command:

$ brew tap-new GITHUBID/tap

Homebrew will try to connect this to a tap at, which you presumably will not have, and that’s ok as we want a local-only tap.

Then extract the version you want to your tap (we’ll pretend it’s for this example):

$ brew extract --version= clojure GITHUBID/tap

This will look through the github commit history for the Homebrew core tap to find the old version’s files, then extract them to your local tap. You then need to install them with:

$ brew install clojure@

If for some reason you’ve already done this, you might need to reinstall instead.

And finally, to actually tell brew to symlink this old version in over the current version, do:

$ brew link --overwrite clojure@