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 Mac OS X instructions for my recommendations.
- Start a terminal
- Make sure Java is installed
- Get Leiningen installed
- Test installation
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.
Go ahead and open your terminal now. It should look something like this:
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
java -version in your terminal. If you do not have Java installed, OS X will prompt you to install it. Follow all of the directions OS X gives you, 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:
The details of Java's version may differ from what you see above; that is perfectly fine.
Leiningen is a tool used on the command line to manage Clojure projects.
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
curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > lein sudo mkdir -p /usr/local/bin/ sudo mv 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 me 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. Make sure you have a terminal open for testing.
Go to your terminal and run the following command:
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:
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!
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.
ClojureBridge Curriculum by ClojureBridge is licensed under a Creative Commons Attribution 4.0 International License.