Vincent Prouillet

Hey, it made my day !

Install ibm_db on Ubuntu

Ok so this one was a bit tricky.
I needed to access remote DB2 databases using Python.
I found ibm_db (page here) and followed the instructions.

First you need to set up DB2 drivers : you can get it here (Data Server Driver Package, NOT the ODBC) or here here (I used this one). You will need to create an account for both.
You can then untar the archive, select the good folder (odbc_cli_driver/linuxia32) and untar the archive present there, for example in /home/vincent/db2driver .

If you try to build and install ibm_db right now it will tell you to set up the DB2 environment so let’s do it.

vincent@ubuntu:~$ export IBM_DB_LIB=/home/vincent/db2driver/lib
vincent@ubuntu:~$ export IBM_DB_DIR=/home/vincent/db2driver

You should now be install to build install ibm_db :

vincent@ubuntu:~$ cd /home/Downloads/ibm_db/
vincent@ubuntu:~/home/Downloads/ibm_db/$ python setup.py build
vincent@ubuntu:~/home/Downloads/ibm_db/$ python setup.py install

Try to import it in python and you should get the following error :

vincent@ubuntu:/home/vincent/Downloads/ibm_db-1.0.4# python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db
Traceback (most recent call last):
  File "", line 1, in
ImportError: libdb2.so.1: cannot open shared object file: No such file or directory

Huuum still not working…after a little googling I found how to resolve it in this issue .

You have to do the following :

vincent@ubuntu:~/Downloads/ibm_db-1.0.4$ sudo nano /etc/ld.so.conf.d/db2.conf
[sudo] password for vincent:
vincent@ubuntu:~/Downloads/ibm_db-1.0.4$ sudo ldconfig
vincent@ubuntu:~/Downloads/ibm_db-1.0.4$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db
Traceback (most recent call last):
  File "", line 1, in
ImportError: libstdc++.so.5: cannot open shared object file: No such file or directory

Install the libstdc++5 package and voila!

vincent@ubuntu:~/Downloads/ibm_db-1.0.4$ sudo apt-get install libstdc++5
....
incent@ubuntu:~/Downloads/ibm_db-1.0.4$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db
>>>

It should work now !

Leave a Reply