[Jose Peleteiro] Installing CouchDB on Ubuntu 8

Apache CouchDB is a very nice schema-free document-oriented database that I’m playing with lately.
Here’s a quick guide to get CouchDB running on Ubuntu 8:

Prepare your environment
sudo aptitude install automake autoconf libtool subversion-tools help2man spidermonkey-bin build-essential erlang erlang-manpages libicu38 libicu-dev libreadline5-dev checkinstall libmozjs-dev wget

Create a couchdb user
sudo adduser --no-create-home --disabled-password --disabled-login couchdb

Download and build the latests version
wget http://mirrors.uol.com.br/pub/apache/incubator/couchdb/0.8.1-incubating/apache-couchdb-0.8.1-incubating.tar.gz

tar -xzvf apache-couchdb-0.8.1-incubating.tar.gz

./configure --bindir=/usr/bin --sbindir=/usr/sbin --localstatedir=/var --sysconfdir=/etc


Install it
sudo make install

sudo chown couchdb:couchdb -R /var/lib/couchdb /var/log/couchdb

sudo update-rc.d couchdb defaults

Start the service
sudo /etc/init.d/couchdb start

CouchDB will be running on port 5984. By default it listens only for connections from the local host. To change that edit /etc/couchdb/couch.ini and restart CouchDB.

Sample code (Ruby):

#!/usr/bin/env ruby
# Setup
require "rubygems"
require "couchrest"
require "test/unit/assertions"
include Test::Unit::Assertions
# Database
couchdb = CouchRest.new("http://localhost:5984")
couchdb.database('helloworlds').delete! rescue nil
db = couchdb.create_db('helloworlds')
# Create
  {"_id" => "en", "helloworld" => "Hello world"},
  {"_id" => "pt", "helloworld" => "Ola mundo"}
# Retrive
document = db.get("pt")
assert_equal "Ola mundo", document["helloworld"]
# Update
document["helloworld"] = "Olá mundo!!!"
# Retrive again
assert_equal "Olá mundo!!!", db.get("pt")["helloworld"]
# Fails to delete, since variable msg is an only snapshot of the data
assert_raise(RestClient::RequestFailed) { db.delete(document) }
# But working with a last revision of the document
document_last_revision = db.get("pt")
assert_not_equal document["_rev"], document_last_revision["_rev"]
assert_nothing_raised { db.delete(document_last_revision) }
# Schema free
  {"name" => "Maria Hernandes", "helloworld" => "Oi!"},
  {"name" => "John Wisky", "helloworld" => "Whatzup!", "age" => 24},
  {"helloworld" => "Duuuude!", "age" => 18, "country" => "Australia"},
  {"name" => "Peleteiro", "age" => 29, "country" => "Brazil", "helloworld" => "Olá"},
  {"helloworld" => "Hi guys", "name" => "Michel", "country" => "USA"}