Uncategorized

Running Clojure on the BeagleBone Black

Intro

I’ve found a few articles about using the Clojure programming language on the BeagleBone Black. However, all of them I’ve seen gloss over the installation steps. I got Clojure 1.6.0 running on my rev B BeagleBone Black (aka BBB from here on) and I’ve outlined the steps to do it in this post. If you haven’t done anything with your BBB yet, plug it in to a free USB port and open START.htm when it mounts as a drive.

The Install

Make sure that your BBB has Internet access via Ethernet. Once it’s connected to an Ethernet network (with DHCP) you can find the IP address and use it from there on out. However, first you need to connect to the BBB using ssh and the USB-Ethernet bridge interface.

Listing 1

ssh root@192.168.7.2

Add a new user and set the password so that you won’t have to run as root. Be sure to change jwright to your preferred user name.

Listing 2

useradd jwright -m; passwd jwright

Logout (Ctrl+D) and ssh back in as the new user.

Listing 3

ssh jwright@192.168.7.2

Get the Ethernet IP address (inet addr) if you want.

Listing 4

/sbin/ifconfig eth0

I installed Java 1.7 via the “Installing Oracle’s JDK on BeagleBone Black” instructions here. I’ve summarized and customized the steps below.

Download the Linux ARM v6/v7 Soft Float ABI JDK for the ARM platform. The download requires you to accept a license agreement, so I downloaded it to my laptop and then used scp to copy it over to the BBB. The “7u55″ portion of the filename in Listing 5 may vary for you. Your IP address and user name will also vary, of course. I set up a ~/bin directory for my user to put the files in, but you would usually put Java in a location that’s more accessible system-wide like /usr/bin or /usr/local/bin.

Listing 5

mkdir ~/bin;cd ~/bin;scp jwright@192.168.0.198:/home/jwright/Downloads/jdk-7u55-linux-arm-vfp-sflt.tar.gz ./

Extract the file you downloaded. I rm the file after extraction because of the limited space available on the BBB. If you wanted to be even more efficient you could actually extract the archive as you’re copying it across the network.

Listing 6

tar xvf jdk-7u55-linux-arm-vfp-sflt.tar.gz;rm jdk-7u55-linux-arm-vfp-sflt.tar.gz

Add the JDK to your PATH environment variable and make it permanent in .bashrc. Again, note that the version (55) and user name may vary for you.

Listing 7

cd;echo "export PATH=$PATH:/home/jwright/bin/jdk1.7.0_55/bin" | tee -a .bashrc

Set the JAVA_HOME for your installation, making sure to update the version number and user name.

Listing 8

cd;echo "export JAVA_HOME=/home/jwright/bin/jdk1.7.0_55" | tee -a .bashrc

Source (load) the .bashrc file and double check to make sure that Java is installed correctly.

Listing 9

source ~/.bashrc;java -version

At this point it would be a good idea to reboot your BBB and run the java -version command again to make sure that the changes to your bash profile worked.

Listing 10

su -c /sbin/reboot root

After you log back in and check Java, you can download the current version of Clojure. Please check for the proper download link here.

Listing 11

cd ~/bin;wget http://central.maven.org/maven2/org/clojure/clojure/1.6.0/clojure-1.6.0.jar

You can then start the Clojure REPL and you’re at the starting point for using Clojure on the BeagleBone Black.

Listing 12

java -cp ~/bin/clojure-1.6.0.jar clojure.main

Conclusion

If you’re new to Clojure I highly recommend that you give it a try. If you come from an Object Oriented Programming background it takes a shift in thinking, but it’s well worth the investment. Have a look at clojure.org and their documentation section to get started. They also have a helpful community that seems to be continuously growing.

Resources

  1. Clojure on the Beagleboard
  2. Clojure’s Quick Start Guide
  3. BeagleBone Black Quick Start Guide
  4. Install Java on the BeagleBone Black
  5. Clojure Download Page
  6. Clojure Home Page
  7. Instructions by Adafruit on Installing Alternate OSes on the BBB