Installing Clojure on Ubuntu

March 11, 2016

Summary: The ClojureBridge curriculum includes excellent instructions for installing Clojure on a variety of systems. They are well suited for beginners. I have adapted the Ubuntu instructions for my recommendations.

Outline

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 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.

Go ahead and open your terminal now. It should look something like this:

blank terminal

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."

Making sure Java is installed

Run java -version in your terminal. If you do not have Java installed, Ubuntu will prompt you to install it. It should look something like this:

no java

no java

Follow all of the directions Ubuntu gives you, selecting the package "openjdk-8-jre-headless" then return to this part of the tutorial and run java -version again.

If Java is installed, you will see something like this in your terminal:

Java version

Java version

The details of Java's version may differ from what you see above; that is perfectly fine.

Installing Leiningen

Leiningen is a tool used on the command line to manage Clojure projects.

Go to the Leiningen website. You will see a link to the lein script under the "Install" heading. Right-click that link and choose "Save Link As...". Save it in your Downloads directory.

Leiningen site Leiningen site

After that, run the following commands in your terminal. You will be prompted to enter your password.

sudo mkdir -p /usr/local/bin/
sudo mv ~/Downloads/lein* /usr/local/bin/lein
sudo chmod a+x /usr/local/bin/lein
export PATH=$PATH:/usr/local/bin

After you run the above commands, run the lein version command. 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! If not, ask an instructor for help.

Testing your setup

You have set up Java and Leiningen on your computer--all the tools you will need to run Clojure. Before starting, we need to test them out.

Go to your terminal and run the following command:

lein repl

This could take a long time, and will download many other pieces of code it relies on. You should see lines that start with Retrieving ... on your screen. When it finishes, your terminal should look like the following:

Testing lein repl

Testing lein repl

This is starting a REPL, which we will learn about soon. It's a special terminal for Clojure. At the REPL prompt, type (+ 1 1) and press Return. Did you get the answer 2 back? Great! Everything is working!

For now, press the Control button and D button on your keyboard together (abbreviated as Ctrl+D). This should take you out of the Clojure REPL and back to your normal terminal prompt.

Congratulations! You have Clojure working on your machine!

Acknowledgements

These instructions have been adapated from the ClojureBridge Setup Guide, part of the ClojureBridge curriculum. ClojureBridge is an organization aimed at increasing the diversity of the Clojure community. They put on workshops around the world. You should support them by volunteering or donating.

Creative Commons License
ClojureBridge Curriculum by ClojureBridge is licensed under a Creative Commons Attribution 4.0 International License.

You might also like