Search code examples
perlmodulecpan

Perl modules not loading correctly when running as non-root user


I'm running into an issue with Perl on a linux system.

When installing new modules (as root), I would occasionally have issues where running scripts as a regular user, I would not be able to access the new module without manually going in and chmod 775'ing the module related files and directories.

I recently performed a CPAN upgrade, as well as installing several modules for a new project. Now, Perl has become almost unusable as a regular user, because of errors that don't appear to be permissions related.

For example, the following very simple script runs fine as root, but returns an error run as a regular user:

#!/usr/bin/perl
use strict;
use warnings;
use Scalar::Util;

As you can see, the script literally does nothing except attempt to load the Scalar::Util module. As a regular user, it returns this error:

**List::Util object version 1.21 does not match bootstrap parameter 1.42 at /usr/lib64/perl5/DynaLoader.pm line 223.
Compilation failed in require at /usr/local/lib64/perl5/Scalar/Util.pm line 22.
Compilation failed in require at ./scalar-test.pl line 4.
BEGIN failed--compilation aborted at ./scalar-test.pl line 4**

When I sudo cpan and try install List::Util, I get back: List::Util is up to date (1.42).

CLARIFICATION: This is happening with several modules, not just the one example. It does not appear to affect every module that was upgraded though; it's several though.

The fact that root can run the scripts says to me that either there is another, underlying permissions issue I'm not seeing, OR PERL is configured slightly different in some way for root than my regular account which is causing it not to find this module.

A search for the List.pm file is returning:

 » sudo find / -name List.pm 

/usr/share/perl5/I18N/LangTags/List.pm
/opt/OV/nonOV/perl/a/lib/5.8.8/I18N/LangTags/List.pm
/root/.cpan/build/perl-5.22.1-D0_eFO/dist/I18N-LangTags/lib/I18N/LangTags/List.pm

 » ls -l /usr/share/perl5/I18N/LangTags/List.pm
-rw-r--r-- 1 root root 28826 Nov  6  2014 /usr/share/perl5/I18N/LangTags/List.pm

 » ls -l /opt/OV/nonOV/perl/a/lib/5.8.8/I18N/LangTags/List.pm
-r--r--r-- 1 bin bin 28826 Nov 30  2012 /opt/OV/nonOV/perl/a/lib/5.8.8/I18N/LangTags/List.pm

 » sudo ls -l /root/.cpan/build/perl-5.22.1-D0_eFO/dist/I18N-LangTags/lib/I18N/LangTags/List.pm
-r--r--r-- 1 1018 513 28826 Oct 17 08:32 /root/.cpan/build/perl-5.22.1-D0_eFO/dist/I18N-LangTags/lib/I18N/LangTags/List.pm

System is RHEL 6.6 x64, Perl is v5.10.1


**» type perl**
perl is hashed (/usr/bin/perl)

**» which perl**
/usr/bin/perl 

**» sudo type perl**
sudo: type: command not found 

**» sudo which perl**
/usr/bin/perl

**» echo ${!PERL*}**
[Nothing Returned] 

**» sudo echo ${!PERL*}**
[Nothing Returned]

**» perl -wle 'print join("\n", @INC)'**
/usr/local/lib64/perl5 
/usr/local/share/perl5 
/usr/lib64/perl5/vendor_perl 
/usr/share/perl5/vendor_perl 
/usr/lib64/perl5 
/usr/share/perl5 
[run with sudo returns identical list]

[Edited for brevity] 
cpan[1]> o conf 
$CPAN::Config options from /usr/share/perl5/CPAN/Config.pm: 
build_dir [/root/.cpan/build] 
build_dir_reuse [0] 
build_requires_install_policy [ask/yes] 
connect_to_internet_ok [1] 
cpan_home [/root/.cpan] 
keep_source_where [/root/.cpan/sources] 
make [/usr/bin/make] 
make_install_make_command [/usr/bin/make] 
makepl_arg [INSTALLDIRS=site] 
prefer_installer [MB] 
prefs_dir [/root/.cpan/prefs] 

I redacted a few lines here from other user's folders

 » sudo find / -name Util.pm | grep "List/Util.pm"
/usr/lib64/perl5/List/Util.pm
/usr/local/lib64/perl5/List/Util.pm
/home/{USERNAME REDACTED}/.cpanm/work/1448660183.31550/ExtUtils-MakeMaker-7.10/bundled/Scalar-List-Utils/List/Util.pm
/root/.cpan/build/Scalar-List-Utils-1.42-2c3ONp/lib/List/Util.pm
/root/.cpan/build/Scalar-List-Utils-1.42-2c3ONp/blib/lib/List/Util.pm
/root/.cpan/build/Scalar-List-Utils-1.42-NOwU0A/lib/List/Util.pm
/root/.cpan/build/Scalar-List-Utils-1.42-NOwU0A/blib/lib/List/Util.pm
/root/.cpan/build/perl-5.22.1-D0_eFO/cpan/Scalar-List-Utils/lib/List/Util.pm

Per request of brian d foy, I installed a new module. This module Config::Onion was not previously installed, so nothing old to conflict. The module installs OK, but I created an onion-test.pl script, same as above, and it has the same issue where it only loads the module as root.

 » sudo perl -MConfig::Onion -e 'print "Module: " . $ARGV[0] . "\nVersion: " . $ARGV[0]->VERSION . "\n\n"' Config::Onion
Can't locate Config/Onion.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.

 » sudo cpan
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.10)
Enter 'h' for help.

cpan[1]> install Config::Onion

[Redacted for brevity. No errors noted during this process.]

Result: PASS
  DSHEROH/Config-Onion-1.004.tar.gz
  /usr/bin/make test -- OK
Running make install
Prepending /root/.cpan/build/Config-Onion-1.004-TigyuT/blib/arch /root/.cpan/build/Config-Onion-1.004-TigyuT/blib/lib to PERL5LIB for 'install'
Manifying 2 pod documents
Installing /usr/local/share/perl5/Config/Onion.pm
Installing /usr/local/share/perl5/Config/Onion/Simple.pm
Installing /usr/local/share/man/man3/Config::Onion.3pm
Installing /usr/local/share/man/man3/Config::Onion::Simple.3pm
Appending installation info to /usr/lib64/perl5/perllocal.pod
  DSHEROH/Config-Onion-1.004.tar.gz
  /usr/bin/make install  -- OK

 » cd /usr/local/share/perl5/Config
 » sudo ls -l  Onion
total 4
-r--r--r-- 1 root root 1856 May  9  2014 Simple.pm

 » sudo find / -name Onion.pm
/usr/local/share/perl5/Config/Onion.pm
/root/.cpan/build/Config-Onion-1.004-TigyuT/lib/Config/Onion.pm
/root/.cpan/build/Config-Onion-1.004-TigyuT/blib/lib/Config/Onion.pm


onion-test.pl:

#!/usr/bin/perl
use strict;
use warnings;

use Config::Onion;



 » ./onion-test.pl
Can't locate Hash/Merge/Simple.pm in @INC (@INC contains: /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 /usr/local/share/perl5/Config/Onion.pm line 9.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Config/Onion.pm line 9.
Compilation failed in require at ./onion-test.pl line 29.
BEGIN failed--compilation aborted at ./onion-test.pl line 29.


 » sudo ./onion-test.pl
[No Errors]

Per Ikegami, I ran this command:

sudo chmod -R go+rX                   \
   /usr/local/lib64/perl5        \
   /usr/local/share/perl5        \
   /usr/lib64/perl5/vendor_perl  \
   /usr/share/perl5/vendor_perl  \
   /usr/lib64/perl5              \
   /usr/share/perl5 

Both of my test scripts, with Scalar::Util and Config::Onion are loading the modules without error. I think his solution is the right one for the issue I was having, and I've marked it accordingly. Thanks everyone for your research, and to Ikegami for hitting on the solution.


Solution

  • List/Util/Util.so probably exists twice in

    /usr/local/lib64/perl5 
    /usr/local/share/perl5 
    /usr/lib64/perl5/vendor_perl 
    /usr/share/perl5/vendor_perl 
    /usr/lib64/perl5 
    /usr/share/perl5 
    

    They are different versions. The newer one can only be accessed by root. If this is the problem it will be solved using

    chmod -R go+rX                   \
       /usr/local/lib64/perl5        \
       /usr/local/share/perl5        \
       /usr/lib64/perl5/vendor_perl  \
       /usr/share/perl5/vendor_perl  \
       /usr/lib64/perl5              \
       /usr/share/perl5