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

Hi,

I am trying to set up Moose and to this end used perlbrew to install perl-5.20.3 to a users directory /home/grunt103 and then used perlbrews cpanm to install Moose and all it's dependencies. When the install started I was told "Can't write to /usr/local/share/perl5 and /usr/local/bin: Installing modules to /home/grunt103/perl5". The last on screen message was "Succesfully installed Moose-2.1804"

I have set up a test script with the lines;
use lib qw(/home/grunt103/perl5)
use Moose;

But when I run the script I get the message "Can't locate Moose.pm in @INC" even though it shows the /home/grunt103/perl5 path in @INC

I have searched for a Moose.pm module and found it in three different places;
/home/grunt103/.cpanm/work/1466508369.14292/Moose-2.1804/blib/lib/Moose.pm
/home/grunt103/.cpanm/work/1466508369.14292/Moose-2.1804/lib/Moose.pm
/home/grunt103/perl5/lib/perl5/x86_64-linux-thread-multi/Moose.pm
It is possible that this last location was created by an earlier attempt to install Moose using RPM

If I add /home/grunt103/.cpanm/work/1466508369.14292/Moose-2.1804/lib/ to the 'use lib' path then I no longer get the "Can't locate Moose.pm" but get a variety of messages about not locating the dependencies. When I search to see where .pm modules are installed below the /home/grunt103 directory I find I have more than 400 different unique paths to the modules!

About half are in directories below /home/grunt103/.cpanm/work/1466508369.14292
E.g. /home/grunt103/.cpanm/work/1466439552.5133/Dist-CheckConflicts-0.11/t/lib/basic/
E.g. /home/grunt103/.cpanm/work/1466439552.5133/Module-Runtime-0.014/lib/

Most of the others are in directories below /home/grunt103/perl5/perlbrew/build/perl-5.20.3 though a few are slightly higher up than this location
E.g. /home/grunt103/perl5/perlbrew/build/perl-5.20.3/cpan/ExtUtils-MakeMaker/lib/
E.g. /home/grunt103/perl5/perlbrew/build/perl-5.20.3/cpan/Module-Build/lib/
E.g. /home/grunt103/perl5/lib/perl5

How can I rationalise this into a practical form? Or do I need a code solution to create a single access point?

Thanks for your help

Replies are listed 'Best First'.
Re: @INC not providing path to modules
by hippo (Archbishop) on Jun 22, 2016 at 14:59 UTC

    Try

    use lib '/home/grunt103/perl5/lib/perl5';

    Ignore the .cpan tree because that's just for the tool's own use.

Re: @INC not providing path to modules
by perlfan (Parson) on Jun 22, 2016 at 20:05 UTC
    Are you sure you're using the perl you're expecting?

    It seems like the message, "Can't write to /usr/local/share/perl5 and /usr/local/bin: Installing modules to /home/grunt103/perl5," indicates that you were using system the cpanm installed via system perl to install Moose as an unprivileged user. In any case, you're environment is not what you're expecting it to be.

    Look at the output of which perl and perlbrew list;

      Hi perlfan

      I was using perlbrew's cpanm installer which was installed within the /home/grunt103 directory and it should have been using perl-5.20.3 also installed within the /home/grunt103 directory. I was not surprised by the message as grunt103 would not have had permission to write to the directories outside of it's domain.

      I have pasted the full message below in case there is something in there I have missed.

      ! Can't write to /usr/local/share/perl5 and /usr/local/bin: Installing modules to /home/grunt103/perl5
      ! To turn off this warning, you have to do one of the following:
      ! - run me as a root or with --sudo option (to install to /usr/local/share/perl5 and /usr/local/bin)
      ! - Configure local::lib in your existing shell to set PERL_MM_OPT etc.
      ! - Install local::lib by running the following commands
      !
      ! cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)

      I have copied Moose.pm to /home/grunt103/perl5 and the script can find Moose so I might uninstall all the modules and use local::lib to install them all into /home/grunt103/perl5

      Thanks for your feedback.

        If you don't want to see that message, I recommend following the instructions in it:

        Configure local::lib in your existing shell to set PERL_MM_OPT etc.

        I think that local::lib has lots (and lots) of documentation on how to configure it properly for perlbrew etc.

Re: @INC not providing path to modules
by OpenSpace (Novice) on Jun 22, 2016 at 15:13 UTC

    Thanks Hippo, just tried that path again but it still gives me a can't find Moose message :(

      I have managed to solve this problem by using cpan instead of cpanm

      I deleted perlbrew, perl-5.20.3 and all the modules installed for Moose and started again.

      I re-installed perlbrew and perl-5.20.3 and used cpan to install Moose

      It did not work first time, for some reason cpan just stopped and returned to the command prompt soon after starting without any error message. I executed again the command to install Moose and this time it ran all the way through to the 'success' message

      There were quite a few 'module not found' messages in the output but so far they have not caused any errors.