Update: If you’re looking for instructions for Ubuntu 12.04 and later, most of the steps below still apply, but there are a few small differences nicely explained by Rob Staveley at http://bimport.blogspot.com.au/2012/05/using-perl-dbi-with-oracle.html
Update 2: It turns out these steps can be used for Cygwin as well. Thanks to Marc for pointing it out.
couple of weeks few years ago I finally got a new laptop at work – which meant of course that I had to reinstall everything. Although we used Windows XP, there was one app that I had to run through Linux. The solution was VirtualBox running Ubuntu. When I tried to run the app, I realized that I still needed to Install DBD::Oracle and Oracle Instant Client on Ubuntu – which brings me to this article. Nothing better than a reinstall to generate article material 🙂
DBD::Oracle is usually a pain to install if you haven’t already done it a gazillion times. After that, it’s just an annoying itch. In this article I’ll cover installing DBD::Oracle using Oracle Instant Client, Ubuntu 9.04 (at the time – I’ve had reports that this works on 12.04 and up), and Perl 5.10. Since we’re using the Instant Client, you’ll need an Oracle DB you can connect to in order to do the testing. You can choose to skip testing altogether, but you might be into an unpleasant surprise later.
DBI and DBD::Oracle
Installing the DBI is always easy – regardless if you’re running Windows or Linux. Just follow the steps.
- Get root password if you don’t already have one:
sudo passwd root
- Switch to root:
- Run CPAN:
perl -MCPAN -e shell
- Check if DBI is already installed:
- If it’s not installed, install it:
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.
- Check for DBD::Oracle:
- Download it:
- Exit CPAN:
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
Oracle Instant Client Download Site i386
Oracle Instant Client Download Site AMD64 32- and 64-bit
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.
AMD64 has only zip files from what I could find, and they’re named a bit differently, too (remove the 32 for the 64-bit version:
Note: Extract the zips into a directory called instantclient and skip to the Set Up your Environment Variables section if you’re using the AMD64 or i386 zip files.
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-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):
Update: If you get an ELFCLASS64 error, try setting LD_LIBRARY_PATH to $ORACLE_HOME/lib32 instead.
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
It’s time to finally install DBD::Oracle. Go to your CPAN build directory and
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.
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!