Installing CouchDB on MacOSX
If you, like me, have been keeping an eye on the extremely interesting CouchDB Project then maybe you’ve thought about playing around with it a bit on your Mac. This turns out to be very simple.
I assume you have macports w/ subversion (and XCode, of course) installed already. Most of this comes straight from the Readme but I hate reading those, I just want someone to write what I have to do - maybe you do too, so here you are!
UPDATE: 11th October
Reinstalling after noticing 60 commits in 3 days .. now that’s active development.
Step 1 - Get the Prerequisites
CouchDB is written in erlang and needs some goodies to work properly. No problem, they’re in macports. Open a terminal and type:
sudo port install automake autoconf libtool help2man erlang icu
It might spit out some errors saying automake’s already installed, if so, great! Ignore them.
That’s going to take a while. While we wait, let’s open another terminal windows and grab the latest trunk.
Step 2: Get the Source
You can probably find a .tar.gz archive on the site, but all the cool kids will do this:
cd ~/Desktop svn co http://couchdb.googlecode.com/svn/trunk/ couchdb
That will also take a while. When both steps are finished, time for …
Step 3: Configure and Install
Got all the stuff you need? Great. Time to install this mofo.
Firstly, if you use macports (of course you do) then you probably like sticking stuff in /opt/local. So let’s set Couch to install there.
cd couchdb ./bootstrap ./configure --prefix=/opt/local
There’s a bunch of other options you can choose in configure, run
./configure --help
to see them all.
If that finished with no errors, ready to make and install:
make && sudo make install
Done. Time to run:
sudo couchdb
Well, now it’s running. What next? Ruby!
I assume you have rubygems installed - if not, install them and then run this:
sudo gem install couchobject
When that’s done, fire up irb and let’s check this baby out:
Shadow:~ sho$ irb -rubygems irb(main):001:0> require 'couch_object' => true
Let’s see if there’s any databases already
irb(main):002:0> CouchObject::Database.all_databases("http://localhost:8888") => []
Nope. So let’s create one:
irb(main):003:0> CouchObject::Database.create!("http://localhost:8888", "sailor") => {"ok"=>true} irb(main):004:0> CouchObject::Database.all_databases("http://localhost:8888") => ["sailor"] irb(main):005:0> db = CouchObject::Database.open("http://localhost:8888/sailor") =>#<:database:0x1451ea0> =8888, =#<:http localhost:8888 open="false">, ="localhost", @uri=#<:http:0xa28e42 url:http:>>, @uri="http://localhost:8888", ="sailor"> irb(main):06:0> db.name => "sailor"
Looking good. And now let’s check out one of couchdb’s most compelling features: its native REST interface:
http://localhost:8888/_all_dbs
["sailor"]
http://localhost:8888/sailor
{”db_name”: “sailor”, “doc_count”:0, “update_seq”:0}
Insert a record:
irb(main):015:0> db.post("", JSON.unparse({"hello" => "kitty"})) => #<:response:0x1442284>"2712769932", "_id"=>"4E628D72A7F5B5694FA1A2697EEFDF68", "ok"=>true}, =#<:httpcreated created readbody="true">> irb(main):017:0> db.get("_all_docs") => #<:response:0x143c474>[{"_rev"=>"2712769932", "_id"=>"4E628D72A7F5B5694FA1A2697EEFDF68"}], "view"=>"_all_docs"}, =#<:httpok ok readbody="true">> irb(main):018:0> db.get("4E628D72A7F5B5694FA1A2697EEFDF68") => #<:response:0x1437d34>"2712769932", "_id"=>"4E628D72A7F5B5694FA1A2697EEFDF68", "hello"=>"kitty"}, =#<:httpok ok readbody="true">>
http://localhost:8888/sailor/4E628D72A7F5B5694FA1A2697EEFDF68 (obviously, the GUID will be different if you try that)
{”_id”:”4E628D72A7F5B5694FA1A2697EEFDF68″,”_rev”:”2712769932″,”hello”:”kitty”}
We are happy.
Check out more in the CouchObject RDOCs at rubyforge.
It’s very exciting to see progress in the development of this promising new DB technology, and from within Ruby!