I am new to Perl so please bear with me. Thank you for your assistance.
I have an Ubuntu machine with Perl on it. I followed the local::lib bootstrapping guide
I used cpanm to install DBI and other modules to my system. I am concerned there may be other DBI modules available on my system which could be part of the problem. This is the result of find / -name 'DBI.pm' 2>/dev/null:
/home/ubuntu/.cpanm/work/16125643.6178/DBI-1.643/blib/lib/DBI.pm
/home/ubuntu/.cpanm/work/16125643.6178/DBI-1.643/blib/lib/Bundle/DBI.pm
/home/ubuntu/.cpanm/work/16125643.6178/DBI-1.643/DBI.pm
/home/ubuntu/.cpanm/work/16125643.6178/DBI-1.643/lib/Bundle/DBI.pm
/home/ubuntu/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/DBI.pm
/home/ubuntu/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/Bundle/DBI.pm
I added 2 lines to my .bashrc file. (I added the second line because I broke things for the non-root user and this fixed it; maybe I broke something with local::lib?)
eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"
PERL5LIB="/home/ubuntu/perl5/lib/perl5"
I can run my perl script as a non-root user.
If I run with sudo perlScript.pl I get this error: Can't locate DBI.pm in #INC (you may need to install the DBI module)
I have been troubleshooting #INC for a while now and cannot figure out how to adjust it for the root user. I have tried various things including adding PERL5LIB to .profile and calling my script like so: sudo sh -c '. ~/.profile; perl ~/perlScripts/perlScript.pl "argForScript"' (I verified that PERL5LIB is being set with sudo sh -c '. ~/.profile; echo $PERL5LIB')
However I always get the #INC error. The most obvious thing I have noticed is comparing sudo perl -V and perl -V. The sudo call does not show any ENV vars and the #INC does not include the desired PERL5LIB location. The non-sudo call does show the desired ENV and #INC vars.
I am considering wiping things and doing a fresh install with root privileges for local::lib and cpan. Not really sure what else to try at this point.
These are the commands that ended up working for me. I corrupted my first environment with local::lib / non-sudo cpan install, so I setup a fresh VM.
sudo apt install make
sudo apt install build-essential
sudo apt install libmysqlclient-dev
sudo cpan App::cpanminus
cpanm --sudo DBI
cpanm --sudo Array::Utils
cpanm --sudo DBD::mysql
Related
Hi I am trying to install VelvetOptimizer using docker. and it say Can't locate Bio/SeqIO.pm in #INC. It requires the following to be installed:
Velvet >= 0.7.51 ,Perl >= 5.8, BioPerl >= 1.4 and i have installed them
Please find the Dockerfile:
FROM amazonlinux
WORKDIR /shared
RUN yum -y install gcc
ADD http://www.cpan.org/src/5.0/perl-5.16.1.tar.gz /shared
RUN tar -xzf perl-5.16.1.tar.gz
WORKDIR /shared/perl-5.16.1
RUN ./Configure -des -Dprefix=/shared/perl-5.16.1/localperl
RUN make
RUN make test
RUN make install
RUN echo “Perl Installation Complete”
ENV PATH=/shared/perl-5.16.1/localperl/bin/:${PATH}
WORKDIR /shared
ADD http://www.ebi.ac.uk/~zerbino/velvet/velvet_latest.tgz .
RUN tar -xvf /shared/velvet_latest.tgz
WORKDIR /shared/velvet_1.2.10/
RUN make
ENV PATH=${PATH}:/shared/velvet_1.2.10/
WORKDIR /shared
RUN echo "BIO PERL INSTALLATION"
RUN \wget -O - https://install.perlbrew.pl | bash
ENV PATH=${PATH}:/root/perl5/perlbrew/bin/
RUN perlbrew install-cpanm
RUN cpanm Bio::Perl
WORKDIR /shared
ADD http://www.vicbioinformatics.com/VelvetOptimiser-2.2.5.tar.gz .
RUN tar zxvf VelvetOptimiser-2.2.5.tar.gz
ENV PATH=${PATH}:/shared/VelvetOptimiser-2.2.4
When I run the command/shared/VelvetOptimiser-2.2.5/VelvetOptimiser.pl
I get the below error:
Error:
Can't locate Bio/SeqIO.pm in #INC (#INC contains: /shared/VelvetOptimiser-2.2.5 /shared/vcftools/src/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /shared/VelvetOptimiser-2.2.5/VelvetOpt/Assembly.pm line 238.
BEGIN failed--compilation aborted at /shared/VelvetOptimiser-2.2.5/VelvetOpt/Assembly.pm line 238.
Compilation failed in require at /shared/VelvetOptimiser-2.2.5/VelvetOptimiser.pl line 37.
BEGIN failed--compilation aborted at /shared/VelvetOptimiser-2.2.5/VelvetOptimiser.pl line 37.
But when I use "find" command: I am able to find the files.
./root/.cpanm/work/1501770319.1/BioPerl-1.007001/blib/lib/Bio/SeqIO.pm
./root/.cpanm/work/1501770319.1/BioPerl-1.007001/Bio/SeqIO.pm
./shared/perl-5.16.1/localperl/lib/site_perl/5.16.1/Bio/SeqIO.pm
I think its not be found in Perl's include path, which is represented by the variable named #INC.
Can anyone please let me know how to fix this issue. how to add it in perls include path.
Clearly, /shared/VelvetOptimiser-2.2.5/VelvetOptimiser.pl has
#!/usr/bin/env perl
as its shebang line. So, it will use the first perl it finds in the $PATH.
You likely have a perl in /usr/bin. In your Docker file, you have:
ENV PATH=${PATH}:/root/perl5/perlbrew/bin/
That is, you likely put /usr/bin ahead of the perlbrew directory. So, /usr/bin/env perl is picking up /usr/bin/perl and not the perl you installed via perlbrew (which is also where you installed your new perl).
So, try
ENV PATH=/root/perl5/perlbrew/bin/:${PATH}
In addition, I do not see you actually install a perl via perlbrew:
You need
perlbrew install 5.xx.x
perlbrew switch 5.xx.x
before installing cpanm and installing Bio::Perl.
I'm trying to install Perl modules Geo::ShapeFile and Math::Round but I keep coming across the same error and I can't find a solution that works. I've local::lib installed fine but its not being found or something? Am I doing it in the wrong place?
cian#cian-Aspire-5750:~/Documents/Math-Round-0.07$ make install
Manifying 1 pod document
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ERROR: Can't create '/usr/local/man/man3'
mkdir /usr/local/man/man3: Permission denied at /usr/share/perl/5.22/ExtUtils/Install.pm line 477.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
at -e line 1.
Makefile:697: recipe for target 'pure_site_install' failed
make: *** [pure_site_install] Error 13
I notice in my directory '/usr/local/man' points to 'usr/share/man'. I dunno if this was an issue how to solve it. Thanks.
I've local::lib installed fine
No, you don't. The environment has clearly not by set by local::lib. Make sure the following in your login script:
eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"
(Adjust the path to local::lib if needed.)
Log out and log back in or use the following to pick up the changes:
exec bash -l
If you want to install module systemwide (it's what you do), you should have root privileges. Try sudo make install or install modules locally.
Alternatively you may try a cpanm client, which handles local::lib installs either:
$ cpanm -l ~/ Geo::ShapeFile Math::Round
And then don't forget to adjust perl5lib var to see installed modules:
$ PERL5LIB=~/lib/perl5
First, some background.
perlbrew is a tool to assist with the installation of Perl into a non-standard directory (usually under your home directory).
It also helps you control which Perl installation is used when executing perl in an interactive shell. Switching between installations is done using perlbrew use and perlbrew switch. perlbrew use only affects the current shell, while perlbrew switch is more permanent.
$ perl -V:version | $ perl -V:version
version='5.20.0'; | version='5.20.0';
|
$ perlbrew use 5.18.2t | $ perlbrew switch 5.18.2t
|
$ perl -V:version | $ perl -V:version
version='5.18.2'; | version='5.18.2';
|
$ bash -ic 'perl -V:version' | $ bash -ic 'perl -V:version'
version='5.20.0'; | version='5.18.2';
perlbrew off is used to revert to using the system Perl, but it's temporary like perlbrew use. Is there a way to revert to the system Perl with the permanency of perlbrew switch?
To have perlbrew manage an installation of perl that wasn't installed by perlbrew, pick a name ("system" in my example) and create a link to its bin directory as follows:
cd "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}"
mkdir perls/system
ln -s /usr/bin perls/system/bin
It will now appear in perlbrew list
$ perlbrew list
...
system (5.10.1)
5.18.2t
* 5.20.0t
...
And you'll be able to use perlbrew use and perlbrew switch.
$ perl -V:version
version='5.20.0';
$ perlbrew switch system
$ perl -V:version
version='5.10.1';
$ bash -ic 'perl -V:version'
version='5.10.1';
This works best with installations that have the same installbin, installvendorbin (if applicable) and installsitebin directories, as returned by
perl -V:'install.*bin'
By the way, a similar approach can be used to create aliases for perlbrew installs. For example,
ln -s 5.26.1 perls/5.26 # Point to the latest release of a version.
ln -s 5.26.1 perls/project_name # Point to the install used by a project.
You can use the following command
perlbrew switch-off
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!
If you have root, type in console (Debian/Ubuntu):
sudo apt-get install libdbi-perl
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'
For redhat/centos users:
sudo yum -y install perl-DBI
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
For alpine users use perl-dbi: apk add perl-dbi
For arch linux users:
sudo pacman -S perl-dbi
I want to run a Catalyst application on my web server, which has system perl v5.10. I want to use at least v5.12 for the app., and I don't want to meddle with the system perl.
Our sysadmin insists that the app. be run by a non-shell user (such as "nobody")
I know I can use perlbrew to use non-system perl for development, but I'm not sure what the best way to then run the live version is. How do people advise handling this situation?
Since you're familiar with perlbrew, you could still use that to install Perl.
perlbrew install 5.16.1 --as=5.16.1t -Dusethreads
You just make sure you give proper permissions. Say your $PERLBREW_ROOT is /home/djh/perl5/perlbrew (the default):
chmod a+x /home/djh/
chmod a+x /home/djh/perl5/
chmod a+x /home/djh/perl5/perlbrew/
chmod a+x /home/djh/perl5/perlbrew/perls/
chmod -R a+rX /home/djh/perl5/perlbrew/perls/5.16.1t/ # Capital "X"!!!
Then use the following shebang line in your script:
#!/home/djh/perl5/perlbrew/perls/5.16.1t/bin/perl
But maybe you don't want it in your home. If so, this is what you can do:
cd /tmp
wget http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/perl-5.16.1.tar.bz2
tar xvjf perl-5.16.1.tar.bz2
cd perl-5.16.1
sh Configure -des -Dprefix=/opt/perls/5.16.1t -Dusethreads
make test
sudo mkdir /opt/perls/5.16.1t
sudo chown djh:djh /opt/perls/5.16.1t
make install
The installer will setup the permissions correctly. All you have to do is set the shebang to
#!/opt/perls/5.16.1t/bin/perl
("t" is my convention for threaded builds. Remove -Dusethreads if you don't want thread support.)
Give nobody (i.e., everybody) read and execute permission to the perl executable(s) and all libraries (everything under the #INC directories).
Change the shebang line in all your applications scripts (including at least everything under your ./scripts directory) to the instance of perl that you want to use. Or if you want to be flexible about out, point the shebang line to a symbolic link that points to a desired perl executable. Make sure this link is also accessible to nobody.
Restart your application whenever you point your symbolic link to a different version of Perl.