Friday, September 19, 2014

Running ClojureCLR 1.6 on Ubuntu 14.04

Recently ClojureCLR 1.6 was released. This post describes how to run ClojureCLR 1.6 on Ubuntu 14.04 - you may be able to run it similarly on other Ubuntu versions.

Installing Mono

The Mono project provides an Open Source implementation of the .NET platform. In order to run ClojureCLR we need to install Mono first. Follow the steps below to install Mono:

1. Create the following directories:
$ mkdir -p ~/app/installed
$ mkdir -p ~/app/src

2. Download the file and untar the file in the src folder:
$ cd ~/app/src
$ tar xvf /path/to/mono-3.8.0.tar.bz2

3. Build Mono binaries from sources:
$ cd ~/app/src/mono-3.8.0
$ mkdir -p ~/app/installed/mono-3.8.0
$ ./configure --prefix ~/app/installed/mono-3.8.0
$ make
$ make install

4. Set the PATH to include the Mono binaries - include following lines in your ~/.bashrc or ~/.zshrc depending upon what shell you use:

export MONO_HOME=~/app/installed/mono-3.8.0
export PATH=$MONO_HOME/bin:$PATH

5. Verify that Mono is configured fine by running the mono command:
$ mono --version
Mono JIT compiler version 3.8.0 (tarball Sat Sep 13 13:21:35 IST 2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors.
 TLS:           __thread
 SIGSEGV:       altstack
 Notifications: epoll
 Architecture:  amd64
 Disabled:      none
 Misc:          softdebug 
 LLVM:          supported, not enabled.
 GC:            sgen

Installing and configuring Nuget

Download the Nuget binary from and put it in a directory that is included in PATH. The Nuget binary being in PATH helps when using the lein-clr plugin.

Using Nuget on Linux requires some additional configuration. Run the following commands (note that mozroots and certmgr binaries are in Mono but may not be visible to sudo, so you may have to give full path):
$ sudo $MONO_HOME/bin/mozroots --import --machine --sync
$ sudo $MONO_HOME/bin/certmgr -ssl -m
$ sudo $MONO_HOME/bin/certmgr -ssl -m
$ sudo $MONO_HOME/bin/certmgr -ssl -m

Installing and configuring ClojureCLR 1.6

To download ClojureCLR 1.6 you can now use Nuget:

$ cd ~/app/installed
$ mono /path/to/nuget.exe install Clojure -Version

This command will download ClojureCLR 1.6 into a folder 'Clojure.' in the current directory. The 'Clojure.' directory contains sub-directories 'lib' and 'tools', each further containing 'net35' and 'net40' sub-directories. You will need to store the files from 'lib' and 'tools' in a common directory, so do as follows:

$ cd ~/app/installed/Clojure.
$ mkdir -p all/net35
$ mkdir -p all/net40
$ cp lib/net35/* all/net35/
$ cp lib/net40/* all/net40/
$ cp tools/net35/* all/net35/
$ cp tools/net40/* all/net40/

Now, in each of 'all/net35' and 'all/net40' sub-directories you need to create symbolic links for the file 'Clojure.dll' - the symbolic link names are listed below:

$ ln -s Clojure.dll
$ ln -s Clojure.dll clojure.core.clj.dll
$ ln -s Clojure.dll clojure.core_clr.clj.dll
$ ln -s Clojure.dll clojure.core_deftype.clj.dll
$ ln -s Clojure.dll clojure.core_print.clj.dll
$ ln -s Clojure.dll clojure.core.protocols.clj.dll
$ ln -s Clojure.dll clojure.core_proxy.clj.dll
$ ln -s Clojure.dll clojure.genclass.clj.dll
$ ln -s Clojure.dll clojure.gvec.clj.dll
$ ln -s Clojure.dll clojure.instant.clj.dll
$ ln -s Clojure.dll clojure.main.clj.dll
$ ln -s Clojure.dll clojure.pprint.cl_format.clj.dll
$ ln -s Clojure.dll clojure.pprint.clj.dll
$ ln -s Clojure.dll clojure.pprint.column_writer.clj.dll
$ ln -s Clojure.dll clojure.pprint.dispatch.clj.dll
$ ln -s Clojure.dll clojure.pprint.pprint_base.clj.dll
$ ln -s Clojure.dll clojure.pprint.pretty_writer.clj.dll
$ ln -s Clojure.dll clojure.pprint.print_table.clj.dll
$ ln -s Clojure.dll clojure.pprint.utilities.clj.dll
$ ln -s Clojure.dll clojure.repl.clj.dll
$ ln -s Clojure.dll clojure.set.clj.dll
$ ln -s Clojure.dll clojure.stacktrace.clj.dll
$ ln -s Clojure.dll clojure.string.clj.dll
$ ln -s Clojure.dll clojure.template.clj.dll
$ ln -s Clojure.dll clojure.test.clj.dll
$ ln -s Clojure.dll clojure.uuid.clj.dll
$ ln -s Clojure.dll clojure.walk.clj.dll

Now ClojureCLR 1.6 is ready to run. For example, you can launch a REPL as follows:

$ mono ~/app/installed/Clojure. -r

You may notice Ctrl+D key combination does not work in this REPL. Use Ctrl+C to exit.

Using ClojureCLR 1.6 from the Lein-clr plugin

1. To use the Lein-clr plugin you need to have Java and Leiningen installed. To create a new lein-clr project use the following command:

$ lein new lein-clr foo

Make sure the lein-clr plugin version is 0.2.2 (or higher) in the project.clj file.

2. Edit the :clj-exe entry (under :clr => :cmd-templates) to specify an environment variable that points to the 'Clojure.' directory we discussed in the previous section.

Now you should be able to use ClojureCLR 1.6 in your lein-clr app:

$ cd foo
$ lein clr repl
$ lein clr test

Hope you find this useful. For more information on ClojureCLR 1.6 you should join the ClojureCLR Google Group. You may like to follow me on Twitter.

Disqus for Char Sequence