46

I have started using perlbrew and installed perl-5.12.2.

I understand I need to re-install my CPAN modules, so I switched to my new Perl version (perlbrew switch perl-5.12.2 and hash -r), verified the switch was successful (perl -v) then tried installing some module (File::Copy::Recursive using cpan. However, cpan says `File::Copy::Recursive is up to date (0.38).

When I start a Perl script using this module, it shouts Can't locate File/Copy/Recursive.pm in @INC ... (showing many perl-5.12.2 locations). When I switch back to my 'normal' Perl (perlbrew off) the script runs fine.

Any suggestions? Perhaps CPAN does not work well with perlbrew?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David B
  • 29,258
  • 50
  • 133
  • 186

3 Answers3

44

After installing perlbrew you could install cpanm through this command:

perlbrew install-cpanm

Otherwise you will need to install cpanm manually each time you switch your Perl version on perlbrew. With this command just once.

Once installed you can then use cpanm to install the missing module:

cpanm File::Copy::Recursive
David Gardner
  • 6,952
  • 4
  • 35
  • 37
jacktrade
  • 3,125
  • 2
  • 36
  • 50
  • 15
    Btw., in case you didn't know (as I didn't), cpanm is a cpan alternative, which works better with perlbrew. After installing as above, then you can use, e.g. "cpanm install File::Copy::Recursive", etc. – Joshua Richardson May 05 '14 at 17:10
  • 3
    @JoshuaRichardson: Notice `cpanm install` will try to install `install` module. because `cpanm` has not such command: `Usage: cpanm [options] Module [...]` – Eugen Konkov Jun 14 '18 at 11:15
2

Everything should be working fine with "cpan" as well as "cpanm", that is: when switching perl with perlbrew, cpan sees the installed modules of the version you use.

While it's true that cpanm is the recommended tool to use with perlbrew, cpan allows for test reporting so that is what I always use.

arthas
  • 139
  • 4
1

How do I install CPAN modules while using perlbrew?

That's how:

perlbrew use <version>

cpan -i <module>
Elvin
  • 166
  • 7
  • 1
    There is no "install" command to cpan. Just note the modules that you want to install. – brian d foy May 18 '22 at 14:23
  • Yes, thanks, corrected that, I must have confused the `-i` option for a non-existing `install` subcommand: _-i module [ module ... ]: Install the specified modules. With no other switches, this switch is implied._ – Elvin May 18 '22 at 17:58