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

make

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
db.bulk_save([
  {"_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!!!"
db.save(document)
 
# 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
db.bulk_save([
  {"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"}
])
This entry was posted in Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted August 28, 2008 at 12:21 am | Permalink

    Muito bom, com esse CouchDB é possivel fazer aplicações client-sides inteiras em JavaScript, usando ele como banco remoto. Não sei em que domínio isso seria aplicável, mas a possibilidade é bem interessante.

  2. Posted August 30, 2008 at 1:26 pm | Permalink

    Peleteiro,
    fiquei curioso: o que você usou para converter ruby em syntax-highlighted html? Fiquei muito bom com fundo branco..

    []’s
    Pedro

  3. Posted August 30, 2008 at 2:04 pm | Permalink

    Pedro,
    http://ideathinking.com/wiki/index.php/WordPress:CodeHighlighterPlugin

  4. Posted September 2, 2008 at 4:42 pm | Permalink

    Legal!!!

  5. Posted November 18, 2008 at 2:50 pm | Permalink

    Já instalei em uma VM na minha máquina e vou começar a usar!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*