perllocallib

Upgrade all modules installed by local::lib


I've been using local::lib to handle the installation of Perl modules on a server so I can get the right versions for some development work without polluting the system installation.

However, the system administrator has recently upgraded Perl from 5.16 to 5.18 and I'm now getting errors relating to binary modules, e.g.

perl -e 'use Scalar::Util'
Perl API version v5.16.0 of List::Util does not match v5.18.0 at /usr/lib64/perl5/5.18.2/XSLoader.pm line 92.
Compilation failed in require at /home/paul/perl5/lib/perl5/x86_64-linux/Scalar/Util.pm line 11.
Compilation failed in require at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

My understanding is that I can fix the problem by forcing local::lib to rebuild all of its modules, but I can't find anything in the documentation which tells me how to do this, or even how to get a list of all the modules that have been installed using local::lib (if I had that in a 'one module per line' text file, I could easily write a Bash script to process it).

Is this possible, or do I have to remove the ~/perl5 directory and reinstall all the modules from scratch (possibly missing some as I can't remember them all)?


Solution

  • Update: For some time now, INSTALL_BASE has been producing a better directory structure that avoids this problem for new installs.

    And that's why the perl Makefile.PL INSTALL_BASE=... convention (and the corresponding one for Build.PL) used by install::lib sucks.

    Removing (or renaming the directory so you have backup) is the easiest solution. You can find out what you had installed by looking for .pm files.

    cd ~
    mv perl5{,16}
    cd perl516/lib/perl5
    find -name '*.pm' | xargs perl -MConfig -E'
       for (@ARGV) {
          s!^\./!!;
          s!^5\.\d+\.\d+/!!;
          s!^x86_64-linux/!!;
          s!^auto/!!;
          s!\.pm\z!!;
          s!/!::!g;
          say;
       }
    ' | xargs cpan
    

    (Do a dry run — one without the trailing | xargs cpan — first.)

    Note that if you don't want to be at the mercy of your admin's upgrades, you can use perlbrew to easily install a whole build of Perl in your home dir.