- Start a terminal
- Install Git
- Configure Git
- Make sure Java is installed
- Install Leiningen
- Install Nightcode
- Test your setup
For these instructions, and for much of the class, 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."
To see if you have git installed type in: git --version
If you have git version 1.9.3 (Apple Git-50)
or above you should be fine.
If not, visit git-scm.com. Click "Downloads for Mac". The Git installer may begin downloading automatically. If it does not, click the manual download link. Once the download has finished, open ~/Downloads in Finder and double-click the downloaded file (named something like git-2.0.1-intel-universal-snow-leopard.dmg). This will mount the disk image and open a new Finder window. Double-click the installer package (named something like git-2.0.1-intel-universal-snow-leopard.pkg). You may be told that the installer can't be opened because it is from an unidentified developer. If so, click "OK", then right-click (or control-click) the file and select "Open" from the contextual menu. You may be warned again that the installer is from an unidentified developer, but this time you'll have the option to click "Open". Do so. This will launch the installer. Follow its directions, and enter your password when prompted to do so. Once you have finished this process it's safe to unmount the disk image (by clicking the eject button in the Finder sidebar) and delete the file from the Downloads folder.
If you've used Git before then you should already have user.name and user.email configured. Otherwise, type this in the terminal:
git config --global user.name "Your Actual Name"
git config --global user.email "Your Actual Email"
TIP: Use the same email address for git, github, and ssh.
Verify by typing this in the terminal:
git config --get user.name
Expected result:
your name
git config --get user.email
Expected result:
your email address
If you have OS X version 10.11 (El Capitan), you don't have Java installed. You need to install Java as well. Download Java from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html and follow the instruction. Once installation finishes, set
JAVA_HOME
environment variable on the terminal.export JAVA_HOME=/usr/libexec/java_home -v 1.8
If you have a trouble, the article, http://osxdaily.com/2015/10/17/how-to-install-java-in-os-x-el-capitan/, may help.
Run java -version
in your terminal. If you do not have Java installed, OS X will prompt you to install it (if your OS X is 10.10 or older). 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.
To install lein
, execute the following commands in your terminal; you will be prompted to enter your password for at least the first command starting with sudo
(The %
character is a typical commandline prompt, don't type it):
% 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
Check that you can now see the command:
% which lein
/usr/local/bin/lein
If you don't see /usr/local/bin/lein
as above, do this next:
% export PATH=$PATH:/usr/local/bin
Now run which lein
and you should see the lein
command.
After you set up Leiningen as above, run the lein version
command. This 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 an instructor for help.
Go to the Nightcode releases site.
On the page there, you should see version numbers and links to download specific version of Nightcode, for example, Nightcode-2.1.0.jar.
Click the link ending in .jar
and you will download a file, Nightcode-x.y.z.jar
.
Don't download platform specific binary releases. Use jar archive. Jar archive is much easier to get started.
Once the download finished, we want to start the editor.
To startup, go into your Downloads folder (or wherever you save files from your browser) and run the Nightcode-x.y.z.jar file using java
command.
Open a terminal and run the following commands:
cd ~/Downloads/
java -jar Nightcode-2.1.0.jar
You have set up Java, Leiningen, Nightcode, and Git on your computer--all the tools you will need for this workshop. Before starting, we need to test them out.
Open a new terminal and run the following command:
lein new myproject
This will create a new project, myproject
, which has files to form a Clojure project.
Normally, Clojure code exists within such Clojure project.
Run following commands:
cd myproject
lein repl
This may take long to start up for the first time.
Leiningen downloads libraries it needs to run Clojure.
When Leiningen starts, you'll see user=>
prompt on your terminal.
Now, you are ready to use REPL, which we 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!
Your leiningen install looks good. 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. Then, the terminal will show you the following message: user=> Bye for now!
Open another terminal and run the following command:
git clone https://github.com/ClojureBridge/welcometoclojurebridge
This will clone welcometoclojurebridge
repository which includes sample Clojure apps.
Your terminal should look similar to this picture:
Once it finishes, type following commands on the same terminal.
cd welcometoclojurebridge
ls
You'll see the list of directories/files like this:
README.md outline project.clj resources src
If Nightcode isn't started yet or closed, open it by typing the command on terminal:
java -jar Nightcode-2.1.0.jar
At the bottom right of the screen, type (+ 1 1)
into the window. It should look like the following image:
If you see the result, 2, that worked, great!
Now we will open and run the sample Clojure apps in Nightcode.
On the top left corner, click "Import" then find the directory,
welcometoclojurebridge
, which was created when you ran
git clone
command. Click "Open."
In the project directory tree on the left, click on src
- welcometoclojurebridge
- core.clj
. The core.clj
file will be opened on the right side.
This is a Clojure program.
The next step is to run the code shown in the window.
Click "Run with REPL" on the bottom.
This could take a long time, and will download many other pieces of code the app relies on.
You should see lines that start with Retrieving ...
on your screen.
Eventually, REPL will start and show a prompt, user=>
.
Once, you see the prompt, click "Reload" button.
You should see a fun welcome message.
Let's try one more sample.
In the directory tree on the left, click on
welcometoclojurebridge
- src
- clojurebridge-turtle
-
walk.clj
. The walk.clj
file will open on the right side.
Like we did before, click "Reload" button.
An initial image of the turtles app should pop up. A small triangle on the center is the turtle.
Type (forward 40)
on the repl at the bottom of the window.
You should see the turtle moved upword:
Congratulations! You have opened and run your first Clojure apps, and your install and setup are all completed!
If you want to know what the turtle (a small triangle) can do, see Turtle App API and How to Walk Turtles for more information.