Several people, including myself, would happily ditch their virtual machines and start introducing DB2 into their native Mac development stacks. But this milestone represents much more than the immediate implications would have us believe. A few years ago, the idea of giving away DB2 for free would have been met with rejection. Yet, DB2 Express-C came along, and unlike the other “express” databases, it’s a true production-ready DB2 version that can be used free of charge.

Likewise, the idea of having a DB2 version for Mac was unthinkable up to a few years ago. Yet today we finally have a copy of DB2 Express-C for Mac OS X that’s available for download. Aside from this being an acknowledgment of the growing importance of Mac as a development and business platform, I feel it underlines IBM’s ability to change. The desire that a few of us mac addicts had, coupled with reasonable pressure from the community, was sufficient enough to make DB2 on Mac a reality. This matters and appeals to both the developer and the technical evangelist in me.

In the list of downloads, you’ll notice that the Mac download is only 138 MB, versus the 412 MB of Linux’s 64-bit. The reason for this difference is that DB2 Express-C for Mac currently ships in English only, and at this stage it doesn’t include either DB2 Text Search or the Java based tools like the DB2 Control Center. This lighter package is, in my opinion, a welcome side effect of this brand new beta release.

Getting started with DB2 and Rails on Mac OS X

Since the first download went live on Friday, a newer release that includes a guide for installing DB2 on Mac OS X was published and it incorporates a few changes that will make the lives of developers easier, as they approach building and using drivers (e.g. the ibm_db Ruby gem). If you downloaded this beta version over the weekend, do not worry: just grab – and execute – this shell script (e.g. sudo fixlib.sh). If you are downloading DB2 on Mac now, you won’t need this script of course.

Once you’ve downloaded DB2 for Mac OS X Leopard, please proceed to read this PDF guide, which will tell you everything you need to know (and more) about installing DB2 on your Mac, as well as providing extra details. It’s best not to skip over reading this document, as the installation on Mac OS X requires a few more steps than simply running the setup wizard.

With DB2 installed and started (sudo db2start), and the SAMPLE database created (db2sampl), you’re ready to start playing with this power horse. For details about SAMPLE’s structure you can read this article in the InfoCenter.

To run the DB2 console (known as the Command Line Processor or CLP for short), run:

$ db2

To connect to the SAMPLE database, from within the CLP run:

db2 => connect to sample

Unless you get an error, you should now be ready to query the database. For example, run the following query:

db2 => select count(*) from staff

Then to exit from the CLP, simply run:

db2 => quit

If this sanity test worked well you can proceed with installing the ibm_db gem (which includes the Ruby driver and the Rails adapter for DB2). To do so, run the following, adjusting the path to your own username of course:

If everything is fine and dandy, you should see the message “The staff table contains 35 records.”.

Now that Ruby can talk with DB2, we can move on to Rails. Assuming you have Rails 2.2.x installed, run the following to create a sample bookshelf application:

$ rails books -d ibm_db

This generates a Rails application (as usual) with a config/database.yml file customized for DB2. You’ll notice that unlike with MySQL, the database names are not books_development, books_production and books_test. The names are truncated by default due to the fact that DB2 currently only allows for database names that are up to 8 characters long. Feel free to change the development database in database.yml simply to ‘books’.

As a Rails developer you may also be accustomed to running rake db:create to automatically create the development database, yet this feature is not available for DB2 at this point, so instead you can create the database using the db2 command, as follows:

db2 create database books

DB2 allows you to specify all kinds of options for the creation of databases, but in its simplest form, the line above will work just fine.

Once the development database has been created, you should be able to use Rails with DB2 as you normally would with other database management systems. For example, you could scaffold a resource as follows:

And then visit https://localhost:3000/books to perform CRUD operations on book records.

At this stage, the only caveats are that you’ll have to use the db2 command, rather than ruby script/dbconsole, and that you won’t be able to use the rename_column method in your migrations. On the plus side, you’ll have the XML datatype (t.xml in your sexy migrations) at your disposal, to natively store XML documents and retrieve them through XQuery and SQL/XML.

I really hope that you’ll enjoy DB2 on Mac! Don’t be afraid to ask for help, if you need it, in the DB2 Express-C forum. Oh and we are trying to get the word out there. Your help is highly appreciated. You can promote this story on Twitter, Hacker News, Reddit, DZone, StumbleUpon and Digg.

Disclaimer: The opinions expressed in this post are mine and mine alone, and do not necessarily represents the opinions of my employer, IBM.

Get more stuff like this

Subscribe to my mailing list to receive similar updates about programming.

Share this:

Related

About The Author

Antonio Cangiano

Antonio Cangiano is a Software Development Manager at IBM. He authored Ruby on Rails for Microsoft Developers (Wrox, 2009) and Technical Blogging (The Pragmatic Bookshelf, 2012, 2019). He is also the Marketing Lead for Cognitive Class, an educational initiative which he helped grow from zero to over 1 Million students. You can follow him on Twitter.

Hi Stuart, this DB2 for Mac OS X port doesn’t include the DB2 Administration Server or the Control Center + java based graphical administration tools (Config Assistant, Health Center, etc). All the core command line based client function is available, so you can use that to do admin tasks on your DB2 servers on Unix/Linux/Windows/Mac.

I know that some people want DB2 graphical admin tooling, and there are other alternatives. Right now I’m testing the DB2 Technology Explorer fka db2mc (http://sourceforge.net/projects/db2mc/) on my Mac with the latest DB2 for Mac OS X beta, this is a lightweight web based PHP tool. Once I finish my testing and finish writing up the how-to guide, I’ll make that available. This should help meet your needs for DB2 graphical admin tooling. And did I mention it’s also free ?

I’ve been waiting for this for a long time now and will be installing DB2 on my iMac. When it comes to graphical tools I stumbled over something called RazorSQL that is not for free, but can be run on a Mac and it supports DB2. Did you ever try that tool? If so, what do you think about it?

I’ve successfully installed DB2 V9.5 Express-C on my 10.5.6 Mac OS X system. Creation of the SAMPLE database (db2sampl) worked just fine and first tests (SQL queries, ODBC connects) indicate that the DBMS works as it should.

When I follow Antonio’s recipe (thanks!) to install the ibm_db gem, however, everythings appears to work OK first.
I then stumble quickly, though:

The bus error might be because the DB2 client is not able to find a required library or might be the ipc resources available on the system is less. Could you check if there is a file named libicclib.dylib present in the directory /sqllib/lib32/icc/icclib. If you are seeing a libicclib.so instead of libicclib.dylib please rename the file to libicclib.dylib. With this you should be able to get going with the ibm_db gem without any problems.

If the files specified above are as required, then you would need to check the ipc resources on your system.

many thanks for your reply. You’re pointing at libicclib.dylib and, indeed, I can find this file only in the sqllib/lib64/icc/icclib directory (note: lib64, not lib32). In fact, there is *no* icc subdirectory below sqllib/lib32…

I dug deep into the db2exc_952beta_MAC_x86_64.tar.gz and db2exc_client_952beta_MAC_x86_64.tar.gz files (and the contained tar archives) and can only find the sqllib/lib64/icc directory and its contents. No sqllib/lib32/icc directory at all.