Clojure in 3 Minutes
There are a few different ways to install and configure Clojure. I was shown this way, which seems to be the easiest, most straightforward way of getting Clojure up and running. I’m pretty sure it’s the most straightforward way that I’ve seen of getting any language up and running. Stick with me and you’ll have written your first line of Clojure locally within 3 minutes. Five at the most.
We’re going to use Leiningen to get Clojure installed and running. Taken from the readme file:
Leiningen is for automating Clojure projects without setting your hair on fire.
Working on Clojure projects with tools designed for Java can be an exercise in frustration. With Leiningen, you just write Clojure.
Disclaimer: I’ve only done this on OS X and Linux, but the process should be as straightforward on Windows.
Start the timer. If you care to play along, post a comment when you’re done with your total time from installation to writing line of Clojure and seeing it run.
Before getting started, you should be familiar with your $PATH environment variable. You’ll be downloading a file, and you’ll want to save it to a location that’s currently in the $PATH. If you’re on OS X or Linux, you can type
echo $PATH into a terminal window to see what locations already exist on the PATH. On Windows, the process may vary slightly depending on whether or not you’re running XP or Vista or Windows 7.
OS X and Linux:
- Download the script. Save it as a file named
- Make the file executable:
chmod +x lein.
- Download the Windows Distribution.
- Unzip into a folder that exists in your $PATH.
You might be wondering what step 3 is, because surely it can’t be that simple. Assuming that you’ve got Leiningen set up in a location that’s accessible to your PATH environment variable, it’s that simple.
From a terminal window or command prompt, type the following:
lein repl. Since this is the first time you’re firing up Leiningen, there will be a short pause as the necessary Clojure files are downloaded. This should only occur during this initial run. Within a few seconds, you should see:
You’ve now got a REPL, a Read-Evaluate-Print Loop, and a convenient place to write yourself some Clojure. At the prompt, type the following:
(println "Hello, World. I know Clojure!")
Hit enter, and you should see:
Congratulations! You’ve written and executed your first line of Clojure. Was that 3 minutes?12 comments | 6,227 views