Skip to content

Installation Walkthrough

Brent Millare edited this page Aug 14, 2013 · 13 revisions

Detailed Walkthrough

The goal of this document is to help clojure beginners get up and running.

Update Java

Clojure benefits from the most recent version of Java. You should update your system if possible and ensure that the paths and environmental variables are set.

For windows:

Download the jdk for your system.

You can try adjusting the java Environmental Settings via Control Panel -> Java for system and user, but if that doesn't work, you can also set them manually via (Right Click) My Computer -> Properties -> Advanced System Settings -> Advanced Tab and set JAVA_HOME to something like C:\Program Files\Java\jdk1.7.0_09.

For Ubuntu 12.04 LTS:

Follow this link

In summary, the steps are:

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java7-installer

Installing Git

Git is the version control software we use to manage changes to our sourcecode. I recommend watching this video for a good introduction.

1: Sign up for a github.com account.

2 LINUX: Install git via your package manager software.

Like sudo apt-get install git.

2 MAC: Install git for mac

2 WINDOWS: Install git for windows

Installing leiningen

leiningen2 provides the majority of the functionality you need to use clojure in practice and is a major building block of dj.

1 LINUX: You'll need to create a bin folder for all executables in your PATH, e.g. In a terminal run mkdir ~/bin and echo "PATH=$PATH:~/bin:" >> ~/.bashrc

1 WINDOWS: You'll need to create a bin folder for all executables in your PATH, e.g. In a terminal (open a terminal with hotkey Windows+R and type cmd and ENTER.)

Then in the terminal, type mkdir \Users\%username%\bin or %homepath%\bin (same thing) and add this folder to your PATH.

(ie. on windows 7: Properties on (My )Computer then Advanced System Settings(on the left) then Advanced tab then Environment Variables button then User variables for user, New button, type PATH in Variable Name field and %homepath%\bin; in Variable value field(this will add to the already existing PATH from System variables below but only affects your currently logged in windows user) - you may need to restart any active/already running programs like cmd.exe to see this effect within them)

1 MAC: You'll need to create a bin folder for all executables in your PATH, e.g. In a terminal mkdir /Users/<foouser>/bin and echo "PATH=$PATH:~/bin:" >> ~/.profile

2 LINUX/MAC: Download the install script

2 WINDOWS: Download the install script Also you'll need to download WGET and place it in your %homepath%\bin directory

3: Change directories to the bin folder and run lein self-install.

Installing dj

1 LINUX: in a terminal clone dj with cd ~/; git clone git://github.com/bmillare/dj.git

2 MAC/WINDOWS: Open the github app for MAC/WINDOWS and login.

3 MAC/WINDOWS: Login to github and go to the dj page on github.

4 MAC/WINDOWS: Click the Clone in Mac/Windows button.

Install launcher script

This will make it more convenient to launch a clojure repl. Let me know if you have a better method for starting a leiningen repl in the context of dj.

1 LINUX/MAC: Create the text file dj-repl that looks something like so:

#!/bin/sh
cd ~/dj/
lein repl

or if you want to integrate trampoline and a headless nrepl

#!/bin/sh
cd ~/dj/
lein with-profiles +cljs,+database trampoline repl :headless

and put it in the ~/bin directory

1 WINDOWS: Create the text file dj-repl that looks something like so:

@echo off
cd c:\Users\foouser\dj
c:\Users\foouser\bin\lein.bat repl
:EOF

Be sure to replace foouser with your actual user name. Also, to make this easier to run, in the file browser, right click the script (e.g. right click dj-repl.bat), select Send to -> Desktop (create shortcut). Then you can just double click the shortcut to start a nREPL session.

Build an example project

All projects must be in the ~/dj/usr/src directory.

1: Create directory ~/dj/usr/src/foo

2: Create a project file that looks like so:

(defproject foo "1.0")

See example project.clj for more info

3: Create the src/bar directory ~/dj/usr/src/foo/src/bar

4: Create a sample clojure file ~/dj/usr/src/foo/src/bar/core.clj like so:

(ns bar.core)
(defn my-function [] (println "hello world"))

5: Start a dj-repl by typing in a command prompt dj-repl

REPL stands for READ, EVAL, PRINT, LOOP, since that is the code needed to build a command prompt that you can use.

6: Use dj to add the project to the JVM classpath. With the command in the REPL (dj.dependencies/resolve-project "foo")

The classpath is what the JVM uses to find all the packages it has access to. dj.dependencies/resolve-project will recursively determine and download all the dependencies of a given project, and it will add the packages (aka jar files) into JVM classpath dynamically at runtime.

7: Load the bar.core namespace with (require 'bar.core) in the REPL.

8: Test out function we made with (bar.core/my-function)

(Alternative) Build an example project using leiningen

All projects must be in the ~/dj/usr/src directory.

1: cd ~/dj

2: lein new foo --to-dir usr/src/foo

3: Follow instructions 3 and up from above.

Clone this wiki locally