34

I'm trying to launch this script:

#!/usr/bin/perl 

use DBI;

my $dbh = DBI->connect( 'dbi:Oracle:host=lonlin2;sid=TIMFX1AD;port=1524','xbsesdbo','xbsesdbo123' )  || die ( $DBI::errstr . "\n" );

my $query= "SELECT * FROM product_elements WHERE element_id = 1001";
my $queryHandler= $dbh->prepare($query);

my $result= $queryHandler->execute();


open(fileHandler,"> note.txt");

print fileHandler "Risultato query: $result\n";

my $e= $dbh->disconnect();
close(fileHandler);

When I launch this script I receive this error:

Can't locate DBI.pm in @INC (@INC contains: /opt/perl_32/lib/5.8.3/IA64.ARCHREV_0-thread-multi /opt/perl_32/lib/5.8.3 /opt/perl_32/lib/site_perl/5.8.3/IA64.ARCHREV_0-thread-multi /opt/perl_32/lib/site_perl/5.8.3 /opt/perl_32/lib/site_perl /opt/perl_32/lib/vendor_perl/5.8.3/IA64.ARCHREV_0-thread-multi /opt/perl_32/lib/vendor_perl/5.8.3 /opt/perl_32/lib/vendor_perl .) at ./prova.pl line 3.

I've got all installed! DBI.pm is installed!

Michu93
  • 5,058
  • 7
  • 47
  • 80
chaw359
  • 505
  • 1
  • 5
  • 14
  • 3
    If you installed it, you either installed it using/for a different `perl`, or you instructed Perl to install it to a non-standard directory and you haven't told `perl` to look into that directory. 1) How did you install it? 2) What's the full path to `DBI.pm`? – ikegami Dec 13 '13 at 14:32
  • Try the command `perldoc -l DBI`. If DBI.pm is installed and is in Perl's Include path, you'll see the location of the installation. There could be multiple Perls installed on your system and you might be accessing the wrong one. What's your shebang line like? I use `#! /usr/bin/env perl` to pick up the Perl version my Path uses, and I use [Perlbrew](http://perlbrew.pl) to handle multiple Perl versions. – David W. Dec 13 '13 at 15:48
  • And in which of those directories listed in the error message above is it installed? – runrig Dec 13 '13 at 18:16

6 Answers6

57

If you have root, type in console (Debian/Ubuntu):

sudo apt-get install libdbi-perl
ndmeiri
  • 4,979
  • 12
  • 37
  • 45
Michu93
  • 5,058
  • 7
  • 47
  • 80
12

If you don't have active perl (and hence don't have ppm), you can also get DBI like this:

perl -MCPAN -e 'install DBI'

You may need to install drivers for Postgres like this:

perl -MCPAN -e 'install DBD::Pg'
Nathan Smith
  • 683
  • 1
  • 10
  • 24
user216268
  • 229
  • 2
  • 4
  • Thank you, it works! However, I had to run it with "sudo", since I don't have enough privileges. I have installed it with "sudo perl -MCPAN -e 'install DBI'. – Aleksey Kuznetsov Oct 26 '20 at 07:05
9

For redhat/centos users:

sudo yum -y install perl-DBI
Ankit Agarwal
  • 123
  • 1
  • 2
  • 8
3

DBI isn't in your @INC path, which tells perl where to look for custom modules. This is probably because you've installed them using the cpan tool as a non-root user, which won't have write access to the default include paths.

You will need to locate DBI.pm and other packages, and move them into your @INC path.

Alternatively, find the packages you've installed and add the install path into your library path, for one time use:

PERL5LIB=/path/to/modules perl yourscript.pl

And for a more permanent solution, add this to ~/.bashrc:

export PERL5LIB=/path/to/modules
Glitch Desire
  • 14,632
  • 7
  • 43
  • 55
0

For alpine users use perl-dbi: apk add perl-dbi

William Desportes
  • 1,412
  • 1
  • 22
  • 31
0

For arch linux users:

sudo pacman -S perl-dbi
pfrenssen
  • 5,498
  • 1
  • 22
  • 16