# Learning Clojure/Installation

As of writing, Clojure lacks a standard installer for Windows, and a few packages exist for popular *nix Operating Systems. Although, all examples presented work exactly the same across all systems, regardless of what type of installation you choose.

## Base Installation

A Base Installation is a minimal install that provides all of the capabilities of the Clojure language, but without a GUI or additional interfaces for assistance. Installation with this method has several low level tasks that are not difficult to perform, but may seem difficult to those that have never manually installed a program on a system before.

### Steps

First you should confirm that the Java VM is installed on your machine. This can be easily checked by going to a terminal and typing java -version. If it returns something about your java version, you should be set. If it does not, then you will need to download the Java VM from the Java website.
After you've confirmed that Java is installed on your machine, obtain the most recent version of Clojure from the main Clojure website . This book was written and tested for Clojure version 1.2 (Stable). The file you have downloaded will be a zip file containing several files which are explained in detail in the section Source Install. The file we want is clojure.jar.
Take this file and extract it to any directory of your choice. As this point, you will have a successful installation of Clojure on your machine! All you need to do is to open a command window and type change your directory to where you extracted clojure.jar and type java -jar clojure.jar and you'll be greeted with the Clojure REPL.
Mind you, this is a lot of work just to start Clojure, so we will create a script for each OS that will run the program with a single command and also add this program to the PATH, making the program easily accessible for execution at any time.

### Windows Configuration

First, we need to create a script to run Clojure without the excessive typing. This tutorial assumes that you unzipped clojure.jar to C:\Development\Learning Clojure, and that the below bat file is named clj.bat The below script does just that.
Let's break this down into blocks.
The first few lines that begin with rem are comments. They're present to serve as a reminder of how this bat file works. The next block says that you do not want to see the output of this bat file. This removes command line "noise" when you start Clojure. The next block defines where you installed Clojure and prepares the arguments for when we launch it. Note that the CLOJURE_JAR variable is written in quotes. This is because Java recognizes a space as an end of argument. Thus, without the quotes, the Java command will try to run C:\Development\Learning, which is invalid.
Finally, we have a conditional. The conditional checks to see if there was an argument passed (in our case a clj file). If one was not passed, we will run Clojure's REPL. If one was passed, we will run the passed clj file and also pass any additional arguments to the script.
So we now have our clj.bat which we can run Clojure from easily. Now let's add it to our PATH so that we can execute Clojure from any directory on your system.
This can be done by the following.
* Click Start
* Right Click My Computer
* Select Properties
* Click the Advanced tab
* Click on Environment Variables
If you wish to install this just for the current user, Underneath the "Variables for User" frame, find PATH. If PATH doesn't already exist, click the new button. You'll be greeted with a popup window with the variable name and arguments. For the arguments field, add C:\Development\Learning Clojure. If some value already exists, go to the very beginning and type the same thing, immediately following with a semicolon. Finally click Ok on the Variable Properties screen and Ok again on the Environment Variables Screen.
If you wish to install this for every user on your system, locate the PATH variable underneath the System Variables and perform the same steps as above.
At this point, your system should be set up to run Clojure from any directory. To try it out, click on Start, Run, and then type in clj. You should be greeted with the Clojure REPL.

### Leiningen on windows

Leiningen is a automating tool for clojure. Like Maven for Java, it provides easy and configurable environment for compilation, execution and distribution functionality. It also provides standard convention and project structure. You can download leiningen from https://github.com/technomancy/leiningen, it comes with a batch file and wget.exe for downloading rest of the tool. Site's github page has the details on installation and usage.

### Linux/OSX Configuration

Linux and OSX users follow a similar scripting process to the Windows setup. Below is the script needed to run Clojure:
You should now mark the file as executable by typing chmod a+x clj.bat, and add this directory to your path. This can be done either by a static link to /usr/bin or changing the value of PATH in your .bashrc.
You should now be able to run the Clojure REPL by typing clj at the command prompt.

## Integrated Development Environments (IDE)

Clojure has a few IDEs that makes development easier by providing additional features and utilities. The first and foremost benefit to using an IDE for development is having an all-in-one package. The IDE is your editor, it is your compiler, and it is your build system. The second benefit is that external tools become available, such as source version control systems like Mercurial, Git, and Subversion. Also, IDEs generally make learning a language easier and faster, because most tasks are standardized.
There's also some problems with using IDEs. Using an IDE typically results in a vendor lock-in. If you've written code in one particular IDE, you're not likely to switch to another. Another problem is that IDEs provide a lot of functionality, but sometimes restricts you in areas, such as choosing between Make, Maven, and Leiningen for your build system.
As of writing, there are three major IDEs for Clojure, all which work across Windows, Linux, and OSX.

### Enclojure (Netbeans)

Enclojure is a Netbeans sponsored project which covers a wide array of features.

### Counter Clockwise (Eclipse)

Counter Clockwise is a Eclipse plugin which brings a different look at how Clojure could be integrated into an IDE.

### Swank Clojure (Emacs)

Swank Clojure is a clone of the venerable Slime interface for programming Lisp in Emacs.
These instructions come from: http://riddell.us/ClojureSwankLeiningenWithEmacsOnLinux.html, however that location is not a wiki and there are small fixes that it needs, so I'm copying what was there with those small fixes.
What follows is a description of how to get up and running in Ubuntu.
Install Java
NOTE: If using Lucid Lynx (10.04) or later (and possibly some earlier versions), you will need to first change the apt-get repository so that sun-java6-jdk is available:
~$ sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
(where "maverick" is the adjective descriptor of your ubuntu version ("lucid" for lucid lynx, "maverick" for maverick meerkat, etc.))
~$ sudo apt-get update
Install Ant
Install Maven
Install Git
Install Clojure
* Test Clojure, Gentlemen, start your REPLs.
Install clojure-contrib
Configure Bash Start-up Script
clojure-contrib contains a bash script called clj-env-dir for starting clojure with various options. Edit your ~/.bashrc file to configure this script.
The last line added to the file above sets an alias to the clj-env-dir script. This example uses clj but it could be set to anything.
See the file at ~/opt/clojure-contrib/launchers/bash/clj-env-dir for options.
Add JLine support
Download JLine from http://jline.sourceforge.net/ and unzip and copy jar to the ~/.clojure directory.
Add jline.ConsoleRunner to the last line in ~/opt/clojure-contrib/launchers/bash/clj-env-dir to add JLine functionality.
* Test the Script
To test the new script and verify access to the clojure-contrib library, open a new terminal window and try this:
If any other jars are needed either copy or link them to the ~/.clojure directory.
Emacs support
Install Emacs
Install Slime
Install clojure-mode
Install leiningen
Add the following to .bashrc.
Execute the leiningen script.
Configure Emacs
Add these specifics to the .emacs file.
Test Configuration
Create a test project.
Add the following:
Save and exit the file.
Open a new terminal and open the generated file in emacs:
Connect to the running swank server:
Add some code to the file:
And then at the end of the line, evaluate:
The output will show the configured jar files and their associated paths on the Java classpath.
Lastly, compile the file:

## Source Install

Installation on windows is slightly complicated if you have never modified environment variables or dealt with command-line operations. You will need either the Sun JDK or OpenJDK packages installed on your computer, and you will also need to have Maven installed before attempting this process.

### doc

    Documentation for the Clojure project.

### script

    Test scripts used when building from source

### src

    Java code that your version of Clojure was built on (see Source Install)

### test

    Test scripts that is run when you build Clojure from source

### build.xml

    Build file for Ant compilation

### changes.txt

    Recent changes log.

### epl-v10.html

    The Eclipse Public License

### install

    a Bash script that runs the installation for Clojure

### pom-tempalate.xml

    Build file for Mavin compilation

### readme.txt

    Contains essential information that you should read before installing

## References

* ↑ http://www.java.com/en/download/manual.jsp