How best to handle previously installed modules when upgrading Perl version with homebrew

Viewed 218

I run into this every so often: I run a brew install foobar and as a result, Perl version gets updated. Whenever this happens, the Perl modules that I had installed are no longer found because they were installed in /usr/local/Cellar/perl/5.32.0/lib/perl5/site_perl/5.32.0/ and the new version is now looking in /usr/local/Cellar/perl/5.32.0/lib/perl5/site_perl/5.32.1_1/.

I have/had a ton of modules installed with the previous version and I'd rather not reinstall all of them (at least manually). What's the best way to have the previously-installed modules work with the new Perl version?

For such a small version change above, I could presumably just copy all of the files from the 5.32.0 dir to the 5.32.1_1 dir, but preferably there is a more general and/or robust solution for when the version change is more substantial.

1 Answers

The cpan command can make an "autobundle" file. You'd use the cpan from the prior installation to do this:

$ cpan -a
Creating autobundle in /Users/brian/.cpan/Bundle
Reading '/Users/brian/.cpan/Metadata'
  Database was generated on Fri, 19 Mar 2021 05:41:03 GMT

Package namespace         installed    latest  in CPAN file
Algorithm::C3                  0.11      0.11  HAARG/Algorithm-C3-0.11.tar.gz
Algorithm::Cron                0.10      0.10  PEVANS/Algorithm-Cron-0.10.tar.gz
Algorithm::Diff              1.1903     1.201  RJBS/Algorithm-Diff-1.201.tar.gz
...
version::regex               0.9924    0.9928  LEONT/version-0.9928.tar.gz
vmsish                         1.04      1.04  SHAY/perl-5.32.1.tar.gz
warnings                       1.47      1.47  SHAY/perl-5.32.1.tar.gz
warnings::register             1.04      1.04  SHAY/perl-5.32.1.tar.gz

Wrote bundle file
    /Users/brian/.cpan/Bundle/Snapshot_2021_03_20_00.pm

At the top of that file, there are instructions on installing it. Use the cpan from the new installation to handle this part:

package Bundle::Snapshot_2021_03_20_00;

$VERSION = '0.01';

1;

__END__

=head1 NAME

Bundle::Snapshot_2021_03_20_00 - Snapshot of installation on otter on Sat Mar 20 00:19:35 2021

=head1 SYNOPSIS

perl -MCPAN -e 'install Bundle::Snapshot_2021_03_20_00'

I hardly ever do this though. When I install a new perl and want to use a new project on it, I install the project. That project installs whatever it needs. I like the fresh start instead of carrying over stuff I might not be using anymore.

Also, note that cpan installs the latest versions of whatever you are asking for. If you need particular versions, cpanm is easier to handle. And, in that case, you might consider using a cpanfile to lock down exactly what you want.

Related