How to install Clojure

Sign up for weekly Clojure tips, software design, and a Clojure coding challenge.

Let's get Clojure installed on your system. This guide will help you install the following software.

  • java logo Java Development Kit (JDK)
  • leiningen logo Leiningen - Clojure's most popular project tool
  • clojure logo Clojure Command Line Interface (CLI) (optional, and not yet available for Windows)

The instructions depend on what operating system you are running. Please click your operating system below.

Click your operating system

macOS logo macOS

This guide will help you install the following software.

Starting a terminal

For these instructions, you will need to have a terminal, or command line, open. This is a text-based interface to talk to your computer, and you can open it by running Terminal.app, which is found under /Applications/Utilities. If you have never used the terminal before, you may want to spend some time reading up on command-line basics.

When you open it, it will look something like this:

Blank Mac Terminal

The prompt (where you will type your commands) may look different: it usually shows the computer name and user name, as well as the folder or directory you are currently in.

For the rest of this setup, I will tell you to run commands in your terminal. When I say that, I mean "type the command into the terminal and press the Return key."

java logo Java

I recommend installing Java Development Kit (JDK) version 11 or newer for new installs.

1. Verifying if Java is installed

In your terminal, run the following command:

java -version

It may say something like "-bash: java: command not found". In that case, Java is not installed on your system, and we will need to install it. If it prompts you to install Java, ignore it and cancel anything it opens.

It may output a few lines saying what Java version is installed, like this:

Java Version details

This output indicates java version "1.7.8_45". In the Java world, we ignore the "1." at the beginning. So that's called Java 7. If you have Java less than 11, you will want to upgrade. If you have Java 11, you are done with the Java step. Move on :)

2. Installing or upgrading Java

We need to download JDK 11.

Visit adoptopenjdk.net. It should look something like this:

AdoptOpenJDK for Mac

Select "OpenJDK 11 (LTS)" under "1. Choose a Version". Make sure "HotSpot" is selected under "2. Choose a JVM". Then click the big blue "Latest release" button.

This will download a pkg file. Open that file to begin installing it. A window should open, like this:

AdoptOpenJDK for Mac Installer

Proceed through the steps of the installer. You may "trash" the pkg when you're done.

3. Verify Java again

Open a new Terminal window.

Run the following command:

java -version

It should indicate you have openjdk version 11 or higher.

You're done with Java!

leiningen logo Leiningen

Leiningen is a project tool for Clojure. Most Clojure projects are still built using Leiningen. The projects at PurelyFunctional.tv all use Leiningen.

Leiningen is a command-line tool that is run using the lein command. We will need to install the lein command to your path, which means it will be available to you to run whatever directory you are in.

To install lein, execute the following commands in your terminal. You will be prompted to enter your password. If you are having trouble calling sudo with the message "User is not in sudoers file, incident reported", follow these instructions to add give your account sudo permissions.

1. Download the lein script

curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > lein

2. Move the lein script to the user programs directory

sudo mv lein /usr/local/bin/lein

3. Add execute permissions to the lein script

sudo chmod a+x /usr/local/bin/lein

4. Verify your installation

You should be installed now. Run the following command to test it out.

lein version

It should take a while to run, as it will download some resources it needs the first time. If it completes successfully, you are golden!

clojure logo Clojure Command-Line Interface

The Clojure Command-Line Interface (CLI) is a relatively new (2018) addition to the Clojure tooling world. It is the official way to run Clojure applications. Many people are using it now instead of Leiningen. However, Leiningen is still very popular and all of the courses here on PurelyFunctional.tv still use Leiningen. You won't need it for the courses here, but it is a good idea to install it.

1. You will need Homebrew

Homebrew is a package manager for macOS. It is a common tool for developers to use on Macs.

The Clojure CLI is installed using Homebrew. Type the following command to update the Homebrew package repository.

brew update

If it looks like it ran, you're good to move onto the next step. If the system complains that the brew command is not found, then you will need to install Homebrew. To do that, execute the following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

This will explain what it will do and wait for you to confirm it.

2. Installing Clojure CLI

Now that you have Homebrew ready, execute the following:

brew install clojure/tools/clojure

This will install the Clojure CLI.

To upgrade from a previous install:

brew upgrade clojure/tools/clojure

3. Verifying the installation

Now that it's all installed, run the following to test it out:

clj

It should start a REPL, which looks like this:

Clojure REPL on Mac

If you've got that, then you're ready to roll!

linux logo Linux

This guide will help you install the following software.

Starting a terminal

For these instructions, you will need to have a terminal, or command line, open. This is a text-based interface to talk to your computer. In Ubuntu you can open it by clicking "Dash Home" and typing Terminal. You can also open a terminal at any time by pressing CTRL-ALT-T. If you have never used the terminal before, you may want to spend some time reading up on command-line basics.

It should look something like this:

Linux Blank Terminal

The prompt (where you will type your commands) may look different: it usually shows the computer name and user name, as well as the folder or directory you are currently in.

For the rest of this setup, I will tell you to run commands in your terminal. When I say that, I mean "type the command into the terminal and press the Return key."

If you're not using Ubuntu, open your terminal. The commands we type will be the same.

java logo Java

I recommend installing AdoptOpenJDK Java Development Kit (JDK) version 11 or newer for new installs.

1. Verifying if Java is installed

In your terminal, run the following command:

java -version

It may say something like "-bash: java: command not found", or it may suggest a package to install. Ignore it. In either case, Java is not installed on your system, and we will need to install it.

It may output a few lines saying what Java version is installed. The first line will indicate the version of Java.

If the version starts with a "1.", then you should drop the "1." and read the number immediately after that. So if it's "1.7.8_45", you should drop the "1." and read that as "Java 7".

It may not have the "1.". For instance, it may say "java version 10.45". In that case, that's Java 10.

We need Java 11, so if the number is less than 11, we need to upgrade. If you have Java 11 or higher, you can move on to installing Leiningen. :)

2. Installing or upgrading Java

We have some commands to run in the terminal. These instructions are for Ubuntu and Debian. If you are running another distribution of Linux, follow the instructions here.

1. Allow extra repositories

apt-get install -y software-properties-common

2. Get the AdoptOpenJDK GPG Key (for encryption)

wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -

3. Add the AdoptOpenJDK repository

sudo add-apt-repository —yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/

4. Update the repository index

sudo apt-get update

5. Install AdoptOpenJDK 11

sudo apt-get install -y adoptopenjdk-11-hotspot

3. Verify Java again

Run the following command in the terminal.

java -version

It should indicate you have openjdk version 11 or higher.

You're done with Java!

leiningen logo Leiningen

Leiningen is a project tool for Clojure. Most Clojure projects are still built using Leiningen. The projects at PurelyFunctional.tv all use Leiningen.

Leiningen is a command-line tool that is run using the lein command. We will need to install the lein command to your path, which means it will be available to you to run whatever directory you are in.

To install lein, execute the following commands in your terminal. You will be prompted to enter your password.

1. Install curl command

sudo apt-get install -y curl

2. Download the lein script

curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > lein

3. Move the lein script to the user programs directory

sudo mv lein /usr/local/bin/lein

4. Add execute permissions to the lein script

sudo chmod a+x /usr/local/bin/lein

5. Verify your installation

You should be installed now. Run the following command to test it out.

lein version

It should take a while to run, as it will download some resources it needs the first time. If it completes successfully, you are golden!

clojure logo Clojure Command-Line Interface

The Clojure Command-Line Interface (CLI) is a relatively new (2018) addition to the Clojure tooling world. It is the official way to run Clojure applications. Many people are using it now instead of Leiningen. However, Leiningen is still very popular and all of the courses here on PurelyFunctional.tv still use Leiningen. You won't need it for the courses here, but it is a good idea to install it.

1. Install dependencies

sudo apt-get install -y bash curl rlwrap

2. Download the install script

curl -O https://download.clojure.org/install/linux-install-1.10.2.774.sh

3. Add execute permissions to install script

chmod +x linux-install-1.10.2.774.sh

4. Execute the installer

sudo ./linux-install-1.10.2.774.sh

5. Verifying the installation

Now that it's all installed, run the following to test it out:

clj

It should start a REPL, which looks like this:

Clojure REPL on Linux

If you've got that, then you're ready to roll!

windows logo Windows

This guide will help you install the following software on Windows 10.

Starting a terminal

For these instructions, you will need to have a terminal, or command line, open. This is a text-based interface to talk to your computer. In Windows 10, you can open it by searching for "command prompt" in the search bar then clicking on the Command Prompt app.

Searching for "command prompt"

If you have never used the terminal before, you may want to spend some time reading up on command-line basics.

It should look something like this:

Windows Blank Terminal

The prompt (where you will type your commands) may look different: it usually shows the folder you are currently in.

For the rest of this setup, I will tell you to run commands in your terminal. When I say that, I mean "type the command into the terminal and press the Return key."

java logo Java

I recommend installing Java Development Kit (JDK) version 11 or newer for new installs.

1. Verifying if Java is installed

In your terminal, run the following command:

java -version

It may say something like "'java' is not a recognized command'". If it does, that means Java is not installed and we will need to install it.

It may output a few lines saying what Java version is installed. The first line will indicate the version of Java.

If the version starts with a "1.", then you should drop the "1." and read the number immediately after that. So if it's "1.7.8_45", you should drop the "1." and read that as "Java 7".

It may not have the "1.". For instance, it may say "java version 10.45". In that case, that's Java 10.

We need Java 11, so if the number is less than 11, we need to upgrade. If you have Java 11 or higher, you can move on to installing Leiningen. :)

2. Installing or upgrading Java

We need to download JDK 11.

Visit adoptopenjdk.net. It should look something like this:

AdoptOpenJDK for Windows

Select "OpenJDK 11 (LTS)" under "1. Choose a Version". Make sure "HotSpot" is selected under "2. Choose a JVM". Then click the big blue "Latest release" button.

This will download a msi file (installer). Open that file to begin installing it. A window should open, like this:

AdoptOpenJDK for Windows Installer

Proceed through the installer with the defaults.

3. Verify Java again

Open a new command prompt, then run the following command:

java -version

It should indicate you have openjdk version 11 or higher.

You're done with Java!

leiningen logo Leiningen

Leiningen is a project tool for Clojure. Most Clojure projects are still built using Leiningen. The projects at PurelyFunctional.tv all use Leiningen.

Leiningen is a command-line tool that is run using the lein command. We will need to install the lein command to your path, which means it will be available to you to run whatever directory you are in.

To install lein, execute the following commands in your command prompt. You will be prompted to enter your password.

1. Download the lein.bat script

curl -O https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein.bat

2. Create a bin directory for scripts

md bin

3. Move the lein.bat script to that directory

move lein.bat bin

4. Add bin to your path

setx path "%path%;%USERPROFILE%\bin"

5. Complete your installation

Close the command prompt and open a new one. Then run the following command to finish the installation.

lein self-install

It should take a while to run, as it will download some resources it needs the first time. If it completes successfully, you are golden!