areldy_exten has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I installed the latest stable perl 5.32.0 using perlbrew. And I installed a bunch of modules using cpanm (which I installed using perlbrew instal-cpanm).

When I run $PERLBREW_ROOT/perls/perl-5.32.0/bin/perl -V, it shows the INC having perls/perl-5.32.0/lib/site_perl* and perls/perl-5.32.0/lib/5.32.0*.
But not perls/perl-5.32.0/lib/perl5.

Why isn't this included automatically in the @INC?

I am planning to install modules in this perl's lib using
cd $PERLBREW_ROOT/perls/perl-5.32.0 cpanm -L . MODULE

Many of the modules get installed in the perl5/ path. And so aren't visible for the scripts.

Thank you!

Replies are listed 'Best First'.
Re: Why is lib/perl5 not added to INC for perls installed using perlbrew
by kcott (Archbishop) on Sep 11, 2020 at 13:39 UTC

    G'day areldy_exten,

    Welcome to the Monastery.

    I also have Perl 5.32.0 installed using Perlbrew. From the description of your setup, mine seems to be identical; of course, mine may differ from yours in areas that you haven't mentioned.

    $ perlbrew list * perl-5.32.0 perl-5.30.0 $ which perl /home/ken/perl5/perlbrew/perls/perl-5.32.0/bin/perl $ echo $PERLBREW_ROOT /home/ken/perl5/perlbrew $ $PERLBREW_ROOT/perls/perl-5.32.0/bin/perl -V Summary of my perl5 (revision 5 version 32 subversion 0) configuration +: ... @INC: /home/ken/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/cy +gwin-thread-multi /home/ken/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0 /home/ken/perl5/perlbrew/perls/perl-5.32.0/lib/5.32.0/cygwin-threa +d-multi /home/ken/perl5/perlbrew/perls/perl-5.32.0/lib/5.32.0 $ ls -l $PERLBREW_ROOT/perls/perl-5.32.0/lib/perl5 ls: cannot access '/home/ken/perl5/perlbrew/perls/perl-5.32.0/lib/perl +5': No such file or directory
    "Why isn't this included automatically in the @INC?"

    Short answer: because it doesn't exist.

    Longer answer. I've been using Perlbrew for a very long time, certainly more than a decade, and I don't recall $PERLBREW_ROOT/perls/<install-name>/lib/perl5 ever being a standard Perlbrew directory. This would be why such a path would not be automatically added to @INC.

    I'm not a user of cpanm, I use cpan. As such, I'm not in any position to comment on your use of cpanm beyond suggesting that you check that you are using it correctly. I know cpanm is widely used: if you have questions about that, you can definitely get help about it here.

    If you have modules installed in non-standard locations, consider using PERL5LIB (see "perlrun: ENVIRONMENT") or use the lib pragma. There are other ways of dealing with this but that's probably jumping the gun and heading off-topic for the current issue.

    Minor in-joke for anyone who recalls "Re^4: [OT] 'perl' is not the 'perl' reported by 'which perl'": yes, I did remember type but thought which was more appropriate here. However, just for completeness:

    $ type perl perl is /home/ken/perl5/perlbrew/perls/perl-5.32.0/bin/perl

    — Ken

      "I've been using Perlbrew for a very long time, certainly more than a decade, and I don't recall $PERLBREW_ROOT/perls/<install-name>/lib/perl5 ever being a standard Perlbrew directory."

      None of my perlbrew installations have such a directory either. And I do use cpanm.

        Thank you kcott and tobyinky for the replies.

        My purpose is to install a self-contained perl and a collection of modules all together.
        Such that I can have my scripts work seamlessly by just pointing the shebang to the perl bin.
        E.g.  $PERLBREW_ROOT/perls/perl-5.32.0/bin/perl in this case.

        As I mentioned in my post I installed the modules by doing
        cd $PERLBREW_ROOT/perls/perl-5.32.0 cpanm -L . MODULE
        The cpanm is localed at $PERLBREW_ROOT/bin/cpanm
        This has resulted in the following tree (truncated):
        perls \-- perl-5.32.0/ |-- bin/ | |-- cpan* | |-- perl* | |-- perl5.32.0* | \-- zipdetails* \-- lib/ |-- 5.32.0/ | |-- AnyDBM_File.pm | |-- App/ | |-- x86_64-linux-thread-multi-ld/ | \-- XSLoader.pm |-- perl5/ | |-- Alien/ | |-- alienfile.pm | |-- x86_64-linux-thread-multi-ld/ | \-- XML/ \-- site_perl/ \-- 5.32.0/
        As you can see it has created the perl5/ folder I mention.

        Could you please suggest the correct way to install modules in this perl lib such that the module files sit in the given lib/5.32.0 or lib/site_perl area?

        Thank you again!
Re: Why is lib/perl5 not added to INC for perls installed using perlbrew
by perlfan (Parson) on Sep 11, 2020 at 16:35 UTC
    By default, $HOME/perl5 is where perlbrew puts all its stuff, including perlbrew itself. This can be adjusted when you install perlbrew using an environmental variable (PERLBREW_ROOT I think). I assume you already added the appropriate file you need to source on login to $HOME/.bash_profile or $HOME/.bashrc. You probably also installed cpanm via perlbrew install-cpanm. Both "binaries" perlbrew and cpanm are used no matter what perl you use. I do not recommend adding a directory in @INC that is outside of the isolated perl environments you're created with perlbrew, unless it's via FindBin and managed directly in any Perl programs you're writing. The idea is that perl and all modules installed via cpanm. Unfortunately while perlbrew does a phenomial job at allowing one to manage perl environmental contexts, it's isolation stops there. For example, any modules that rely on libraries installed on the system (e.g., libopenssl) will all find the same libraries unless you've taken the steps to install your own set of libraries and fiddled your LD_* environmental variables appropriately.