I am using CentOS, and I have installed Perl 5.20 and Perl 5.10 was present by default.
I am using the Perl 5.20 version to execute the Perl code
I am trying to use the DBI module and get this error
[root#localhost ~]#perl -e 'use DBI;'
Can't locate DBI.pm in #INC (you may need to install the DBI module) (#INC contains: /usr/local/lib/perl5/site_perl/5.20.1/i686-linux /usr/local/lib/perl5/site_perl/5.20.1 /usr/local/lib/perl5/5.20.1/i686-linux /usr/local/lib/perl5/5.20.1 .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.
How to check for all installed versions of Perl?
How do I check whether the DBI or any module is installed?
How to resolve this error so that I can use DBI module?
How to check for all installed versions of perl?
As Sobrique suggested in comments, you should never touch system perl. I'd suggest using perlbrew. With perlbrew you can install different versions of perl from local user, and to check all installed versions of perl using perlbrew just do $ perlbrew -l.
how to switch between them while executing a program?
Install multiple perls
$ perlbrew -v install perl-5.20.0
$ perlbrew -v install perl-5.13.4
Switch between them
$ perlbrew switch perl-5.20.0
$ perlbrew switch perl-5.13.4
See this article for more details: Installing Multiple Perls with App::perlbrew and App::cpanminus
How do I check if DBI or any module is installed?
How can I check if a Perl module is installed on my system from the command line?
How to resolve this error so that I can use DBI module?
What's the easiest way to install a missing Perl module?
A Guide to Installing Modules
Related
I am trying to use the module DateTime in CentOS so I installed it like this:
yum install perl-DateTime
and then added use DateTime to my script, but I get this error:
Can't locate Sub/Identify.pm in #INC (#INC contains:
/root/perl5/lib/perl5/5.16.3/x86_64-linux-thread-multi
/root/perl5/lib/perl5/5.16.3
/root/perl5/lib/perl5/x86_64-linux-thread-multi /root/perl5/lib/perl5
/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
/root/perl5/lib/perl5/namespace/autoclean.pm line 200. Compilation
failed in require at /root/perl5/lib/perl5/DateTime/Locale.pm line 11.
BEGIN failed--compilation aborted at
/root/perl5/lib/perl5/DateTime/Locale.pm line 11. Compilation failed
in require at /usr/lib64/perl5/vendor_perl/DateTime.pm line 45. BEGIN
failed--compilation aborted at
/usr/lib64/perl5/vendor_perl/DateTime.pm line 45. Compilation failed
in require at myscript.pl line 8. BEGIN failed--compilation aborted
at myscript.pl line 8.
I have no idea what's going on. I already installed several packages through the CPAN. This is the first time I've tried with yum install and it doesn't work. Any ideas?
TL;DR
This is why it's a bad idea to mix modules installed via a package manager and via CPAN.
It looks like you installed DateTime with yum, but DateTime::Locale with CPAN. You can see this by following the dependency chain in your error message:
/root/perl5/lib/perl5/namespace/autoclean.pm --> CPAN
/root/perl5/lib/perl5/DateTime/Locale.pm --> CPAN
/usr/lib64/perl5/vendor_perl/DateTime.pm --> yum
The newest version of namespace::autoclean depends on Sub::Identify, which seems to be missing from #INC.
So did yum install a package with missing dependencies? Nope, it installed an older version of DateTime::Locale, when namespace::autoclean wasn't a dependency:
$ cpan -D DateTime::Locale | grep -oP '[\d.]+(?=\s+up)' # newest version
1.14
$ yum info perl-DateTime-Locale | grep -oP 'Version\D+\K.+' # yum version
0.45
$ rpm -q --requires perl-DateTime-Locale | grep autoclean
$
But since you put /root/perl5/lib/perl5 before the system perl directories in #INC, you're loading the version installed by CPAN, which does need namespace::autoclean and Sub::Identify. Of course, yum has no way to know that.
I'm not sure why Sub::Identify is missing...you may have deleted it, or it may simply be installed outside of #INC. You could try to re-install it with CPAN, but it would be better to:
remove /root/perl5/* from #INC and only install modules in the system perl with yum
use perlbrew or plenv to create your own local installation of perl and install modules with cpan
Hi I am trying to install bugzilla in my dedicated server with perl version 5.8.8. After installing necessary modules.
I tried to install "DBD-Pg" module via "perl install-module.pl DBD-Pg" command.
When I ran the above command I am getting the following error
Attempt to free unreferenced scalar: SV 0x16dac960, Perl interpreter: 0x16a9c010
at /server_path/support/httpdocs/Bugzilla/Install/Util.pm line 20.
Afterwards I try install other modules, but the result is same. How can I resolve this issue. I cannot uninstall perl, because if I do that it will impact my production site. I have zero knowledge on perl. Please suggest.
I've never seen this "install-module.pl" before.
Usually you'd use either CPAN or the packages from your OS to install perl modules.
Debian systems (like ubuntu) can do
apt-get install libdbd-pg-perl
Red-hat systems (like centos and suse) should be
yum install perl-DBD-Pg
Or simply use "CPAN".
cpan -i DBD::Pg
Many sites (including various SO articles) talk about using "rename" using Perl expressions to rename files.
This would be perfect, but apparently this is not the rename utility I have, and none of these articles seem to comprehend that there are multiple versions of "rename" and I can't seem to find where to get version that accepts Perl expressions.
How can I get my hands on the more powerful rename utility mentioned here, here, and here?
I'm running Fedora 20. My current rename command is from the util-linux package and apparently I need the Perl version, which is better.
I can only speak for Debian. The two programs are called
/usr/bin/rename.ul from the util-linux package (hence the .ul suffix)
/usr/bin/prename from the perl package
The actual rename command works via the /etc/alternatives mechanism, whereby
/usr/bin/rename is a symlink to /etc/alternatives/rename
/etc/alternatives/rename is a symlink to /usr/bin/prename
The same problem has been bugging me on Cygwin, which is a Red Hat product, so should be more similar to Fedora. I'll have a look on my company laptop on Monday. And I remember the Perl-rename having worked there sometimes. Probably before I installed util-linux.
If you install the Perl-rename to /usr/local/bin it will have precedence over rename from util-linux. Same goes for the manpage when installed to /usr/local/share/man/man1/.
I've just created a separate Perl-rename package on Github: https://github.com/subogero/rename
You can install it using cpan, which is the perl repository similar to pip for python.
Here is a tutorial on using cpan.
If you try to run rename it it looks like this
rename --help
call: rename from to files...
To install the perl rename you can do the following. You might need to install a few dependencies, you can generally just push enter
cpan
cpan1> install File::Rename
CPAN: Storable loaded ok (v2.20)
Going to read '/root/.cpan/Metadata'
Database was generated on Wed, 30 Sep 2015 08:17:02 GMT
Running install for module 'File::Rename'
....
Running Build install
Installing /usr/local/share/man/man1/rename.1
Installing /usr/local/share/perl5/File/Rename.pm
Installing /usr/local/share/man/man3/File::Rename.3pm
Installing /usr/local/bin/rename
Writing /usr/local/lib64/perl5/auto/File/Rename/.packlist
RMBARKER/File-Rename-0.20.tar.gz
./Build install -- OK
That is how you would install the rename from cpan.
Next is to get it working on your system. As you might have more then one rename installed.
which rename
/usr/bin/rename
When you actually want this one.
/usr/local/bin/rename --help
Usage:
rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E *perlexpr*]*|*perlexpr*
[ *files* ]
Options:
-v, -verbose
Verbose: print names of files successfully renamed.
-n, -nono
No action: print names of files to be renamed, but don't rename.
-f, -force
Over write: allow existing files to be over-written.
-h, -help
Help: print SYNOPSIS and OPTIONS.
-m, -man
Manual: print manual page.
-V, -version
Version: show version number.
-e Expression: code to act on files name.
May be repeated to build up code (like "perl -e"). If no -e, the
first argument is used as code.
-E Statement: code to act on files name, as -e but terminated by
';'.
I just put it into /usr/bin/ but with a slight different name to make sure I did not break any existing scripts / programs the depend on the old one.
ln -s /usr/local/bin/rename /usr/bin/rename.pl
I had to do the following:
# In bash
sudo yum install perl-CPAN
sudo cpan
# In CPAN shell
install Module::Build
install File::Rename
On RedHat 8.4
sudo yum install perl-CPAN
sudo cpan
install module::Build
install File::Rename
than you can create an alias:
alias prename='/usr/local/bin/rename'
an use:
touch pic.jpeg
prename 's/\.jpeg$/.jpg/' *.jpeg
For Debian-family (.deb) distros, I recommend #SzG's answer.
For RedHat-family (.rpm) distros (e.g. Fedora), if your time is precious (like mine), you can download, compile, and install, from source via cpan in one, terse command:
# Install (replace `rename-1.9` below with another version if desired)
curl -L "http://search.cpan.org/CPAN/authors/id/P/PE/PEDERST/rename-1.9.tar.gz" | tar -xz && ( cd "rename-1.9"; perl "Makefile.PL"; make && make install )
# Cleanup
rm -rf "rename-1.9"
Note:
INSTALL_BASE can be set to modify the base installation directory.
e.g. perl "Makefile.PL" INSTALL_BASE=/usr/local
source
For Arch Linux, its
sudo pacman -S perl-rename
I created a post about Perl's rename for many distro:
https://unix.stackexchange.com/a/727288/12574
rpm based distros:
dnf install prename
archlinux:
pacman -S perl-rename
*BSD:
pkg install p5-File-Rename
Debian like/Ubuntu
apt install rename
slackware:
slackbuild
I recently had to install the glorious Perl rename package to Alpine Linux in a Docker container for a Gitlab CI/CD operation:
apk update
apk add --no-cache make perl-utils
cpan File::Rename
In our development environment, another team is using default Perl. So we shouldn't touch it. How do I install another Perl? How do I install Perl modules using CPAN?
anyenv is a great platform to install local versions of all the great open environments, Perl included:
$ git clone https://github.com/riywo/anyenv ~/.anyenv
$ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(anyenv init -)"' >> ~/.bash_profile # change profile if needed
$ exec $SHELL -l
This will set up anyenv. From here, you will install plenv, the Perl environment tool. Each of the environment tools allows you to manage that languages different installed versions.
$ anyenv install plenv
Now we can work with the plenv tool...
List available Perl versions:
$ plenv install --list
Install the Perl 5.18.2 binary:
$ plenv install 5.18.2 -Dusethreads
Change global default Perl to 5.18.2:
$ plenv global 5.18.2
Change local project Perl to 5.18.2:
$ plenv local 5.18.2
Run this command after installing a CPAN module, containing an executable script:
$ plenv rehash
Install cpanm to the current Perl:
$ plenv install-cpanm
Install any modules you need from CPAN with
$ cpanm JSON
I use Carton to manage dependencies within a project and recommend you take a look at it.
Now that you have anyenv, remember you can explore different versions of other languages too. anyenv is a priceless tool.
$ anyenv install --list
Available **envs:
denv
jenv
luaenv
ndenv
phpenv
plenv
pyenv
rbenv
That's what perlbrew is about.
After installing perlbrew, e.g. via
$ curl -L http://install.perlbrew.pl | bash
(or App::perlbrew from CPAN), you can use
$ perlbrew install perl-5.18.2
$ perlbrew switch perl-5.18.2
You need to download and install Perl from source. You may download Perl from http://www.perl.org/get.html.
In order to use another cpan from another Perl version you may not type "cpan" due to the fact that your Linux user will execute the default locations. Instead you have to execute your "alternate" cpan with the full alternate path. Execute with root and clear the hidden cpan folder from ".cpan" from user home.
I'm trying to install some perl module but everytime this message is shown
New CPAN.pm version (v2.00) available.
[Currently running version is v1.960001]
You might want to try
install CPAN
reload cpan
to both upgrade CPAN.pm and run the new version without leaving
the current session.
I've tried to do
install CPAN
reload cpan
With
pi#raspbmc:~$ sudo perl -MCPAN -e shell
Terminal does not support AddHistory.
cpan shell -- CPAN exploration and modules installation (v1.960001)
Enter 'h' for help.
cpan[1]> install CPAN
But the result is
Going to read '/root/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Going to read '/root/.cpan/sources/modules/02packages.details.txt.gz'
Database was generated on Mon, 28 Oct 2013 23:41:06 GMT
HTTP::Date not available
..............
New CPAN.pm version (v2.00) available.
[Currently running version is v1.960001]
You might want to try
install CPAN
reload cpan
to both upgrade CPAN.pm and run the new version without leaving
the current session.
...............pi#raspbmc:~$
The version is still 1.960001.
The following procedure
kuz1#banana:~$ sudo perl -MCPAN -e shell
cpan[1]> install CPAN
cpan[2]> reload cpan
works for me on the BANANA Pi Single-Board Computer with Ubuntu 14.04.
download CPAN module from this page http://metacpan.org/pod/CPAN
untar it (tar zxf CPAN-2.00.tar.gz), cd into the directory and run
perl Makefile.PL
make test
sudo make install
edit: if it breaks making a path with :: in it then perhaps your filesystem type does not support these characters in a filename
To see the filesystem type, run mount without any parameters and all the mounted filesystems with their types will be shown
The error Can't write-open blib/man3/CPAN::Admin.3pm seems to suggest a filesystem problem, but ext4 in rw mode sounds alright. Try this from the CPAN-2.00 directory
perl -e 'open($f,">blib/man3/CPAN::thisisatest") || die $!;'