12

I am using CentOS 7 and seting up a new server.

Whilst logged in as root, I have installed multiple perl modules through CPAN. Unfortunately, they seem to have installed inside root's home directory. I didn't notice this until all the modules were installed, but most of them have locations like this now:

/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 

This means that, for users other than root, these modules essentially do not exist, as the permissions lock them out of that directory.

I know I could solve this by giving all users read access to /root, but I'd rather not.

So, I have a few specific questions to ask:

  • What did I do wrong? Did I skip an option in CPAN the first time it ran? (CPAN config is pasted below)
  • What is the best way to clean this up? I presume I need to uninstall the modules, change my config, and then reinstall them? Experienced advice is appreciated.
  • What is the ideal general installation directory for CentOS 7? Where do I want to move them to? I assumed CPAN would put them in an ideal default location.

All advice gratefully received.

cat MyConfig.pm

$CPAN::Config = {
  'applypatch' => q[],
  'auto_commit' => q[1],
  'build_cache' => q[100],
  'build_dir' => q[/root/.cpan/build],
  'build_dir_reuse' => q[0],
  'build_requires_install_policy' => q[yes],
  'bzip2' => q[],
  'cache_metadata' => q[1],
  'check_sigs' => q[0],
  'colorize_output' => q[0],
  'commandnumber_in_prompt' => q[1],
  'connect_to_internet_ok' => q[1],
  'cpan_home' => q[/root/.cpan],
  'ftp_passive' => q[1],
  'ftp_proxy' => q[],
  'getcwd' => q[cwd],
  'gpg' => q[/bin/gpg],
  'gzip' => q[/bin/gzip],
  'halt_on_failure' => q[0],
  'histfile' => q[/root/.cpan/histfile],
  'histsize' => q[100],
  'http_proxy' => q[],
  'inactivity_timeout' => q[0],
  'index_expire' => q[1],
  'inhibit_startup_message' => q[0],
  'keep_source_where' => q[/root/.cpan/sources],
  'load_module_verbosity' => q[none],
  'make' => q[/bin/make],
  'make_arg' => q[],
  'make_install_arg' => q[],
  'make_install_make_command' => q[/bin/make],
  'makepl_arg' => q[],
  'mbuild_arg' => q[],
  'mbuild_install_arg' => q[],
  'mbuild_install_build_command' => q[./Build],
  'mbuildpl_arg' => q[],
  'no_proxy' => q[],
  'pager' => q[/bin/less],
  'patch' => q[/bin/patch],
  'perl5lib_verbosity' => q[none],
  'prefer_external_tar' => q[1],
  'prefer_installer' => q[MB],
  'prefs_dir' => q[/root/.cpan/prefs],
  'prerequisites_policy' => q[follow],
  'scan_cache' => q[atstart],
  'shell' => q[/bin/bash],
  'show_unparsable_versions' => q[0],
  'show_upload_date' => q[0],
  'show_zero_versions' => q[0],
  'tar' => q[/bin/tar],
  'tar_verbosity' => q[none],
  'term_is_latin' => q[1],
  'term_ornaments' => q[1],
  'test_report' => q[0],
  'trust_test_report_history' => q[0],
  'unzip' => q[],
  'urllist' => [q[http://mirror.sov.uk.goscomb.net/CPAN/], q[http://ww
+w.mirrorservice.org/sites/cpan.perl.org/CPAN/], q[http://cpan.mirrors
+.ovh.net/ftp.cpan.org/]],
  'use_sqlite' => q[0],
  'version_timeout' => q[15],
  'wget' => q[/bin/wget],
  'yaml_load_code' => q[0],
  'yaml_module' => q[YAML],
};
1;
__END__
  • 3
    I'm guessing this is the same problem as described in [I installed a module successfully with CPAN, but perl can't find it. Why?](http://stackoverflow.com/q/32726324/176646) – ThisSuitIsBlackNot Nov 10 '15 at 17:46
  • 1
    I can answer your second and third questions thusly: [perlbrew](http://perlbrew.pl/). – Matt Jacob Nov 10 '15 at 19:19
  • If you're using the system Perl, then did you try to install the modules using `yum`? – Dave Cross Nov 11 '15 at 10:40
  • 1
    I installed what I could using yum, but a lot of older modules needed to be installed with CPAN because of lack of availability on yum. It is the modules installed with CPAN that are installed within /root. – Richard of Essex Nov 11 '15 at 11:01
  • @ThisSuitIsBlackNot - You are correct. Thank you for creating that FAQ. I have been reading that post and the local::lib docs, but I am not clear on what the best way for me to clean this up would be. From the advice in your post, I am thinking that using local::lib with a more accessible location is the best approach, so as to avoid conflicts with yum installed modules. Can I just reconfigure CPAN with a new local::lib directory and leave the current versions in place? Or is it safe to delete /root/perl5 ? – Richard of Essex Nov 11 '15 at 13:51
  • 1
    @Blast If you are administering a system for multiple people, I wouldn't use local::lib. local::lib is more for creating your own personal module directory, like when you don't have admin rights; anybody who wanted to use modules from your local::lib would have to add a `use local::lib '/path/to/dir'` to each of their scripts, or set some environment variables. I think it would be better to only install modules with yum, or to build a new Perl and use CPAN. See [Perl in RPM-Land](http://mag-sol.com/talks/yapc/2008/rpm/rpm.pdf) by Dave Cross as well as *(continued)* – ThisSuitIsBlackNot Nov 13 '15 at 20:34
  • 1
    *(continued)* [CPAN RPMs in RHEL / CentOS : generation, conflict, and solutions](https://www.dark.ca/2010/04/08/cpan-rpms-in-rhel-centos/). As for cleanup, I *think* you can safely blow away `/root/perl5` (don't forget to remove the local::lib-related environment variables from root's .bashrc). Notice there's nothing in your cpan configuration about your local::lib; that is all controlled by environment variables. – ThisSuitIsBlackNot Nov 13 '15 at 20:38

2 Answers2

8

Simplest solution (logged in as root)

vi ~/.bashrc

comment out the following lines:

    #export PERL_LOCAL_LIB_ROOT="$PERL_LOCAL_LIB_ROOT:/root/perl5";
    #export PERL_MB_OPT="--install_base /root/perl5";
    #export PERL_MM_OPT="INSTALL_BASE=/root/perl5";
    #export PERL5LIB="/root/perl5/lib/perl5:$PERL5LIB";
    #export PATH="/root/perl5/bin:$PATH";

Log out, log back in as root, and now cpan will install to the correct system directories.

I would just delete the /root/perl5 directory and start afresh.

CompuLingus
  • 161
  • 1
  • 3
0

You installed modules as root, that's what you did wrong :) Module installation involves running lots of code (including module tests) that you'll never inspect and from people you don't know and shouldn't trust.

By default, CPAN.pm is going to look at the setup of your Perl to decide where to install the modules. It wants to put them in one of the directories in the default @INC.

I'm not a CentOS user, but my advice is to install a different perl for users. You don't want to mess up the perl that your system needs to do its housekeeping work.

You can also configure CPAN to install in a particular location.

Community
  • 1
  • 1
brian d foy
  • 129,424
  • 31
  • 207
  • 592
  • I don't you sudo for cpan. I either have a user that belongs to the group that owns the Perl directories (in a different perl), or update the system perl through the distro's package manager. – brian d foy Oct 15 '16 at 22:02
  • The user wants to install packages system-wide, using sudo or not and running cpan as root or not changes nothing about how local::lib is killing his needs. – mikebabcock Nov 03 '17 at 14:45