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

Hi monks,

I am on os x El capitan and have perlbrew installed. However, when I install a perl module I can't get it working, because it seems perl is not looking at the right place.

Can't locate WWW/Mechanize.pm in @INC (you may need to install the WWW::Mechanize module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2/darwin-thread-multi-2level /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .)

also

 which perl returns  /opt/local/bin/perl5

my understanding is that it should return the path to perlbrew install and not the system perl.

and  perl -v returns  This is perl 5, version 22, subversion 2 (v5.22.2) built for darwin-thread-multi-2level and I indeed used perlbrew to install and switch to perl 5.22.2 but it seems somehow, the "switch" was only partial. What am I missing here?

Thanks

Replies are listed 'Best First'.
Re: @INC not set for perlbrew
by FryingFinn (Beadle) on Jul 25, 2016 at 18:53 UTC

    Try installing cpanm into your perlbrew bin

    perlbrew install-cpanm

    Your path (echo $PATH) should have $HOME/perl5/perlbrew/bin fairly near the front!

    then when you install w cpanm it should load into the correct perlbrew selected version.

      Thanks... It seems for now I found a work around by adding  eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib) in my /.zshenv

        I'm not familiar with the zsh shell, but I'm pretty sure that shouldn't be necessary.

        How did you install perlbrew? Did you follow the basic steps on the perlbrew website?

        Were you logged in as the same user you're trying to install modules under? As FryingFinn stated, installing a perlbrew specific cpanm should be all you need after a typical install.

Re: @INC not set for perlbrew
by sn1987a (Curate) on Jul 26, 2016 at 12:10 UTC

    When I install with perlbrew in linux, It always automatically installs cpanm

    I indeed used perlbrew to install and switch to perl 5.22.2 but it seems somehow, the "switch" was only partial.

    How did you switch to perlbrew version? There are two different commands that have different effects. Using perlbrew use ... only affects the current shell. In another shell or later session, you are back to using the previous version. perlbrew switch ... will permanently use the specified version.

    What is the output of perlbrew list? That will list all of the installed version and flag the current one.

Re: @INC not set for perlbrew
by kcott (Archbishop) on Jul 29, 2016 at 15:41 UTC

    G'day Alessandro,

    I have Mac OS X v10.10.3 (Yosemite) and perlbrew v0.73. If you're not already familiar with certain issues with El Capitan, take a look at "CPAN on El Capitan", "OSX Server Perl install modules" and "apple.stackexchange.com: 'What is the “rootless” feature in El Capitan, really?'".

    which finds the first occurrence in $PATH. Your $PATH should look like this:

    ...:/path/to/perlbrew/bin:...:/path/to/system/bin:...

    Here's my system perl, current perl and $PATH:

    $ /usr/bin/perl -v ... (v5.18.2) built for darwin-thread-multi-2level ... $ which perl /Users/ken/perl5/perlbrew/perls/perl-5.24.0t/bin/perl $ perl -v ... (v5.24.0) built for darwin-thread-multi-2level ... $ echo $PATH $PERLBREW_ROOT/bin:$PERLBREW_ROOT/perls/perl-5.24.0t/bin:...:/opt/loca +l/bin:...:/usr/bin:...

    When you use perlbrew switch, perlbrew should update $PATH; which will now find a different version of perl; the system perl is unaffected.

    $ perlbrew switch perl-5.22.0t $ /usr/bin/perl -v ... (v5.18.2) built for darwin-thread-multi-2level ... $ which perl /Users/ken/perl5/perlbrew/perls/perl-5.22.0t/bin/perl $ perl -v ... (v5.22.0) built for darwin-thread-multi-2level $ echo $PATH $PERLBREW_ROOT/bin:$PERLBREW_ROOT/perls/perl-5.22.0t/bin:...:/opt/loca +l/bin:...:/usr/bin:...

    If you're not seeing this type of behaviour, study the App-perlbrew README (especially the INSTALLATION section), then consider one of the upgrade or install related functions in perlbrew.

    "... but it seems somehow, the "switch" was only partial."

    'perlbrew switch' affects the shell in which it is run, and all shells subsequently created, until another 'perlbrew switch' is executed. It doesn't affect other shells which exist when it is used.

    If that doesn't help, please provide more details. You should find the guidelines in "How do I post a question effectively?" to be helpful in this regard.

    — Ken

Re: @INC not set for perlbrew
by Anonymous Monk on Jul 25, 2016 at 22:32 UTC

    and have perlbrew installed

    Hi,

    What do you mean by that?