19 October 2011

Installing CouchDB and GeoCouch from Sources on Mac OS X

The installation of CouchDB and GeoCouch from sources are very simple. There are many options how to install it but here I will describe the simplest one and the most suitable for a single developer who need a local CouchDB installed (IMHO, of course).

Install HomeBrew

"Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn't include with OS X." – tells us the HomeBrew homepage. It's just true :)
To install HomeBrew follow the steps from HomeBrew's Installation Guide. It's really simple.

Install CouchDB

Use the power of brew:
brew install couchdb

Now you can run couchdb manually with couchdb command.

If you need to run CouchDB automatically on login, run brew info couchdb and do what described.

If you need to run couchdb as daemon with it's own credentials, see CouchDB Installing on OSX.

Test installation

Run CouchDB.
Go to CouchDB's web UI (aka Futon), open "Test Suite" from "Tools" and run all tests.

Install GeoCouch

Get CouchDB Sources

Brew has downloaded the source bundle for us. Let's locate the bundle:
ls `brew --cache`/couch*

Create a directory and unpack source bundle to it:
mkdir couchdb-src
cd couchdb-src
tar --strip-components 1 -zxvf <couchdb-source-bundle-path>
cd ..


Get GeoCouch Sources

Find CouchDB version installed:
brew info couchdb

Checkout GeoCouch code from GitHub. It's important to checkout the right branch depending which CouchDB version you have. Most probably it's CouchDB 1.1.x so you need to checkout the couchdb1.1.x branch:
git clone -b couchdb1.1.x git://github.com/couchbase/geocouch.git
cd geocouch


Build and Install GeoCouch

Build GeoCouch:
export COUCH_SRC=<couch-src-path>/src/couchdb
make


Copy config file:
cp etc/couchdb/local.d/geocouch.ini /usr/local/etc/couchdb/local.d/

Copy test files (change CouchDB version number if needed):
cp share/www/script/test/* /usr/local/Cellar/couchdb/1.1.0/share/couchdb/www/script/test/

Register tests in /usr/local/Cellar/couchdb/1.1.0/share/couchdb/www/script/couch_tests.js (add somewhere in the end of file):
loadTest("spatial.js");
loadTest("list_spatial.js");
loadTest("etags_spatial.js");
loadTest("multiple_spatial_rows.js");
loadTest("spatial_compaction.js");
loadTest("spatial_design_docs.js");
loadTest("spatial_bugfixes.js");


Run CouchDB with GeoCouch

export ERL_FLAGS="-pa <geocouch-path>/build"
couchdb


If your CouchDB is started at login, add to your org.apache.couchdb.plist file (most probably it's inside ~/Library/LaunchAgents/) the following settings:
<key>EnvironmentVariables</key>
<dict>
...
<key>ERL_FLAGS</key>
<string>pa <geocouch-path>/build</string>

</dict>


Note that <geocouch-path> should be absolute and without using of '~'.

Test installation

Start CouchDB as described one step above. Don't forget to specify path to GeoCouch modules or CouchDB will fail on start.
Go to Futon, open "Test Suite" from "Tools" and run all tests or at least "Spatial" and following tests.

Read more about installing/using of GeoCouch.

No comments:

Post a Comment