Sunday, 10 August 2014

Installing CouchDB 1.6.0 on the Raspberry Pi

Update 03.11.2015

The Erlang Solutions Repository now contains a new version of Erlang. The major version is now 18. This is too high for the couch in version 1.6.x.
For this reason, please omit the step of including the Erlang Solutions Repository.
Just rely on what you get from the default Raspbina/Debian repos.
I still have to verify this with Wheezy, but for the new Raspbian Jessie image this does the trick.

Also please note that the couch is now available in version 1.6.1.
The instructions below are valid for this version too, as described here.


Building CouchDB 1.6.0 On Your Pi

CouchDB 1.6.0 has been released and of course we want to have it running on our Pis.
I guess my previous blog on installing version 1.5.1 is still valid but couchDB 1.6.0 is now able to run on Erlang 1.17 and that makes for a sight difference during installation.

Preparing the Pi

Nothing new here...
  • I used a brand new 16 GB card.
  • Download the latest Raspbian Wheezy from www.raspberrypi.org/downloads
    At the time of this writing, the image version was 2014-06-20
  • Install the image on your Pi and do the regular raspi-config
    • Extend the partition
    • Set your locales
    • ...
    • Btw, I did not change the default memory split nor did I overclock
  • Re-boot the Pi for the partition extension to take effect
  • update and upgrade your installation
The Pi is now ready.

Add Erlang Solutions' Repository (omit this step, see update 03.11.2015 hint)

Again, we will not add the Cloudant repository for Spidermonkey, but this time add the Erlang Solutions repository in order to install their Erlang package. This will get you an Erlang 1.17 version which is now ok for couchDB 1.6.0.
The following instructions have been taken from Erlang Solutions' download section:
# 
# Add the following line to your /etc/apt/sources.list:
deb http://packages.erlang-solutions.com/debian wheezy contrib

#Next, add the Erlang Solutions public key for apt-secure using following commans:
wget http://packages.erlang-solutions.com/debian/erlang_solutions.asc
sudo apt-key add erlang_solutions.asc

# update repository cache
sudo apt-get update
#  

Install what's needed

Install the following packages:
#   
# Install Compilers
sudo apt-get install erlang-nox
sudo apt-get install erlang-dev
# Spidermonkey JS engine as lib
sudo apt-get install libmozjs185-1.0
# Development headers for spidermonkey lib
sudo apt-get install libmozjs185-dev
# Dev files for libcurl (openSSL)
sudo apt-get install libcurl4-openssl-dev
# Dev files for icu (Unicode and Locales)
sudo apt-get install libicu-dev
#  

Create an account for couchDB

Next we have to create an account for couchDB:
#   
# Create couchDB account
sudo useradd -d /var/lib/couchdb couchdb

sudo mkdir -p /usr/local/{lib,etc}/couchdb /usr/local/var/{lib,log,run}/couchdb /var/lib/couchdb

sudo chown -R couchdb:couchdb /usr/local/{lib,etc}/couchdb /usr/local/var/{lib,log,run}/couchdb

sudo chmod -R g+rw /usr/local/{lib,etc}/couchdb /usr/local/var/{lib,log,run}/couchdb
#   
The next step is downloading the source code and unpacking it:
(find an appropriate mirror near you)
#   
# Download source and unpack
wget http://ftp-stud.hs-esslingen.de/pub/Mirrors/ftp.apache.org/dist/couchdb/source/1.6.0/apache-couchdb-1.6.0.tar.gz
tar xzf apache-couchdb-*.tar.gz
#   
In order to start the "configure" and "make" process, switch into the couchDB directory:
#   
# Change into the couchDB directory
cd apache-couchdb-1.6.0
#   
Now configure the build:
#   
#Configure the build
./configure --prefix=/usr/local --with-js-lib=/usr/lib --with-js-include=/usr/include/js --enable-init
#  
When configure is through, you should see this message:
“You have configured Apache CouchDB, time to relax.
Run 'make && sudo make install' to install.”
This also tells you what the next step will be: running make and make install.
#   
# running make and make install
make && sudo make install
#   
This will take a couple of minutes. But when its done, you have couchDB 1.6.0 compiled on your pi.

Finally create some soft links, make the service start up at boot-time and start couchDB:
#   
# Start couchDB
sudo ln -s /usr/local/etc/init.d/couchdb /etc/init.d/couchdb
sudo /etc/init.d/couchdb start
sudo update-rc.d couchdb defaults
# see if its running...
curl http://127.0.0.1:5984/
#   

As you can see, the couchDB service binds to localhost.
If you want to reach couchDB from another machine, maybe from another Pi :-), change this.
Open local.ini, find the [httpd] section, activate the binding_address and set it to the IP of your Pi:
#   
# make couchDB accessible within your network
sudo vi /usr/local/etc/couchdb/local.ini
#   
Within this file, find the [httpd] section, activate bind_address and set it to 0.0.0.0
It should now look like this:

[httpd]
;port = 5984
bind_address = 0.0.0.0

As a final test, re-boot your Pi and try to reach couchDB Futon:











And that's it. CouchDB 1.6.0 is running on your Pi.

There is one additional step suggested by a kind reader:
#   
# Now including this hint sent by anonymous
# make couchdb user (created above) owner of local ini-file
sudo chown couchdb:couchdb /usr/local/etc/couchdb/local.ini
#   

Credits

The instructions above are based on an installation guide compiled by Dave Cottlehuber on the new couchDB Confluence Wiki. It describes the process of installing couchDB on a Debian system.
The Wiki entry is here.
I slightly adjusted this process to be working for the Pi too and now with the Erlang Solutions repository included, this guide is even closer to the Wiki than the one for version 1.5.1.