The following instructions are for installing Clojure on Mac OS X 10.11 (El Captain). Although they should work for any *nix based system.
Considering you already have Java and Brew installed (Java 1.5 or greater is require for running Clojure. This already comes pre-installed on OS X).
Set the PATH
The PATH variable tells the Terminal where to find the programs that are about to be installed.
Go ahead and open the ~/.profile and make sure that the PATH variable is set and includes /usr/local/bin and /usr/local/sbin. You should have a line in the file that looks similar to the following, if not add it to the end of the file.
After save file, run the following command:
Donwload and unzip Clojure:
curl -O -J -L http://repo1.maven.org/maven2/org/clojure/clojure/1.7.0/clojure-1.7.0.zip
After unzip open clojure folder and test the build:
java -cp clojure-1.7.0.jar clojure.main
user=> (+ 1 1)
user=> (System/exit 0)
Let’s move jar file:
mkdir /usr/local/lib/clojure && cp clojure-1.7.0.jar /usr/local/lib/clojure/clojure.jar
rlwrap will make interacting with the Clojure REPL much more friendly. It is not necessary but I recommend it. With rlwrap you will have tab completion, parenthesis matching, and much more.
brew install rlwrap
Create clj script:
Copy the following text into the file:
Make the script executable:
sudo chmod +x /usr/local/bin/clj
Now you should be able to run Clojure from the command line:
user=> (+ 3 5)
user=> (def A [[0 1 2] [3 4 5] [6 7 8]])
user=> (let [[x y z] (first A)] (println (+ x y z)))
user=> (println "Hello, World!")
clj run scripts
And that’s it!! :)