How can I move PERLBREW_ROOT to another directory?
Asked Answered
D

1

10

I use perlbrew to manage my Perl environment. When I installed perlbrew the first time as per the documentation, it installed everything to ~/perl5/perlbrew, which I now find undesirable.

The documentation states:

The directory ~/perl5/perlbrew will contain all install perl executables, libraries, documentations, lib, site_libs. In the documentation, that directory is referred as "perlbrew root". If you need to set it to somewhere else because, say, your HOME has limited quota, you can do that by setting PERLBREW_ROOT environment variable before running the installer:

export PERLBREW_ROOT=/opt/perl5/perlbrew
curl -kL http://install.perlbrew.pl | bash

Question: How can I move PERLBREW_ROOT directory to be /opt/perl5/perlbrew instead of ~/perl5/perlbrew?

Daguerre answered 22/9, 2015 at 14:12 Comment(5)
I have not tested this, but since all of the perlbrew information is stored in that single directory ~/perl5. I don't see any reason why you couldn't update PERLBREW_ROOT to point to /opt/perl5 then mv ~/perl5 /opt/perl5. Or depending on how many Perls you have already installed, just rm ~/perl5 and reinstall in /opt/perl5Manrope
@Hunter McMillen, @INC will be all wrong, for one.Astra
@Astra hmm, I would have thought that whenever you perlbrew use vX.XX.XX it would re-examine PERLBREW_ROOT.Manrope
I meant to say perlbrew use vX.XX.XX not simply use.Manrope
@Hunter McMillen, It does. I didn't say it wouldn't find the perl, I said @INC would be all wrong.Astra
A
9

Unfortunately, you cannot simply move an installed Perl. For starters, the paths added to @INC are hardcoded. I present you four solutions, of which I recommend the third.

But first, I recommend using /opt/perlbrew instead of /opt/perl5/perlbrew since there's no need for the extra level. The code snippets below assume you followed this recommendation.

  1. Start from scratch, reinstalling any build of perl you had.

    Con: For each build, you'll also have to reinstall any modules that build had installed. This means you'll need to retest all your applications. This is time consuming, and not without risk.

  2. Move the perlbrew directory, but attempt to fix the installations.

    Move the installation as follows:

    mv ~/perl5/perlbrew /opt/
    # Adjust file ownership and permissions as desired.
    

    Then, edit the paths in each of the files printed by the following:

    for q in /opt/perlbrew/perls/* ; do
       "$q/bin/perl" -le'
          use Config;
          require "Config_heavy.pl";
          print $INC{"Config.pm"};
          print $INC{"Config_heavy.pl"};
       '
    done
    

    You'll also need to edit the shebang (#!) line of many scripts.

    Con: Lots of work (though not nearly as much as the first option), fragile, and not guaranteed to work.

  3. Create future builds in /opt/perlbrew, but keep existing builds where they are.

    After installing perlbrew in /opt/perlbrew, run the following:

    cd /opt/perlbrew/perls
    for q in ~/perl5/perlbrew/perls/* ; do
       ln -s "$q"
    done
    

    Pro: Super simple and quick. Over time, you can phase out your ~/perl5/perlbrew (by deleting unneeded builds, by replacing them as per option 1, or by moving them as per option 2).

    Con: Everyone that should have access to /opt/perlbrew also needs access to your ~/perl5/perlbrew.

  4. Don't change PERLBREW_ROOT. Simply make /opt/perlbrew a symlink.

    ln -s ~/perl5/perlbrew /opt/perlbrew
    

    Pro: Super simple and quick.

    Con: Everyone that should have access to /opt/perlbrew also needs access to your ~/perl5/perlbrew.

Astra answered 22/9, 2015 at 15:22 Comment(4)
That's the reason why I compile all my Perls with -D userelocateableinc.Edwin
@abraxxa, That helps, but you still have to fix all the shebang lines among other things. // Do you know what the downsides are to doing that?Astra
I'm using that on my dev notebook and all prod boxes since years with perlbrew and haven't noticed any side effect so far. The shebang lines are modified from /usr/bin/env perl by Module::Install, not sure if Dist::Zilla also modifies them.Edwin
@abraxxa, Exactly, so you have to change them all if you move the perl build.Astra

© 2022 - 2024 — McMap. All rights reserved.