Perl – Installing DBD::Oracle + Oracle Instant Client


In this article I’ll cover installing DBD::Oracle using Oracle Instant Client, Ubuntu 9.04, and Perl 5.10. Since we’re using the Instant Client, you’ll need some Oracle DB you can connect to in order to do the testing. You can choose to skip testing altogether, but you might be into a surprise later.

DBI and DBD::Oracle

Installing the DBI is always easy – regardless if you’re running Windows or Linux. Just follow the steps.

  1. Get root password if you don’t already have one: sudo passwd root
  2. Switch to root: su –
  3. Run CPAN: perl -MCPAN -e shell
  4. Check if DBI is already installed: m DBI
  5. If it’s not installed, install it: install DBI

That should do the trick for the DBI. The DBD::Oracle is a bit more complicated and we’ll just use CPAN to download it for us. The rest is manual.

  1. Check for DBD::Oracle: m DBD::Oracle
  2. Download it: get DBD::Oracle
  3. Exit CPAN: q

Now we should have the DBD::Oracle distribution downloaded to our CPAN build directory. If you don’t know where to find it, look for .cpan dir under your root home or (if you started CPAN for the first time doing sudo from your main user, look for it under your main user’s home directory). We’ll leave that distro aside for a moment and work on the other pre-requisites.

Oracle Instant Client

Download the instant client packages you’ll need. I chose to download the RPMs and convert them to .deb files using alien. Oracle also provides .zip files if you don’t want to do it the alien way.

Oracle Instant Client Download Site

Accept the license agreement by clicking the Accept radio button. Since the i386 and amd64 files have different names, check the bold words in the file names to know which ones to download (the names below are for the i386 platform). Also, if you don’t have a user_id for Oracle, you’ll be prompted to register one once you click the link. It’s free of charge.

  • oracle-instantclient11.1-basic-xx.x.x.x.x-x.i386.rpm
  • oracle-instantclient11.1-sqlplus-xx.x.x.x.x-x.i386.rpm
  • oracle-instantclient11.1-devel-xx.x.x.x.x-x.i386.rpm


  • oracle-instantclient11.1-basic-xx.x.x.x.x-x.x86_64.rpm
  • oracle-instantclient11.1-sqlplus-xx.x.x.x.x-x.x86_64.rpm
  • oracle-instantclient11.1-devel-xx.x.x.x.x-x.x86_64.rpm

Install alien and libaio

Now is the time to install alien, which is an application that converts rpm files into .deb format to be used with dpkg. Instant Client also requires libaio. Both can be installed through the Synaptic Package Manager. Just open it, look for alien, mark it for install and do the same for libaio and libaio-dev. Once they’re installed, you’re good to move on to install the Instant Client. Just don’t forget to exit Synaptic Package Manager, since we’ll be using dpkg and it won’t work if Synaptic is open.

Install Oracle Instant Client

First step to install Oracle Instant Client from rpm files is to convert them into .deb files. Do that with alien by running the following command (from a command line in the directory where you downloaded your RPMs):

# sudo alien --scripts *.rpm

It takes a little while to run, so be patient. Once it’s complete, install the newly created .deb files:

# dpkg -i *.deb

Set up your Environment Variables

The nasty thing about rpm files is that it’s not always easy to know where the files were installed. If you opted for the zip file approach, your install will most definitely be different. For RPM install, add this to your .bashrc file (swap xx.x for your oracle version):

export ORACLE_HOME=/usr/lib/oracle/xx.x/client

Update: If you get an ELFCLASS64 error, try setting LD_LIBRARY_PATH to $ORACLE_HOME/lib32 instead.

Reload your .bashrc file:

# ~/.bashrc

Note: by default, Oracle Instant Client doesn’t come with a tnsnames.ora file or the directory structure where it’s usually found. We’ll have to create that ourselves –

# mkdir -p $ORACLE_HOME/network/admin; touch $ORACLE_HOME/network/admin/tnsnames.ora

Install DBD::Oracle

It’s time to finally install DBD::Oracle. Go to your CPAN build directory and cd into DBD-Oracle-*. As a user having the environment variable set from the previous section, run Makefile.PL portion.

# perl Makefile.PL

There’s no need to set INC or LIB with the alien approach, but if you run into any issues, try giving Makefile.PL the path to your include dir for INC, and lib dir for LIB.

Next, run

# make

It will raise a few warnings, but unless it exits with an error, you should be OK.

The next logical step is to run make test. However, this will undoubtedly fail unless you have a valid entry in your tnsnames.ora file. If you don’t, you can skip this test and hope that everything works later on. Otherwise, update your tnsnames.ora file with a valid entry, and set one more environment variable before running the test:

# export ORACLE_USERID="user/[email protected]_entry_name"
# make test

This is usually the hardest part to pass with total success. Many things can go wrong. In my case, the valid entry I use doesn’t have full grants to the user I log in as. This always triggers an error on the create/access sequences portion of the testing. I simply ignore it nowadays – make sure you analyze your test results thoroughly before choosing to ignore the errors as well.

Now that the testing is over, simply run

# make install

as a super user and you’re all set!