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

I have a very interesting problem... Our Linux box was rebuilt and Perl was re-installed. I am now trying to install the Perl modules our app needs via CPAN. I was not quite awake when I fired up the CPAN shell as a user instead of as root user. First command I ran was 'install Bundle::CPAN'. But I wasn't in as root user, only as lowly user with limited permissions. I saw a lot of script fly by my eyes, most would test, but none would install because of the limited permissions. D'oh! So I switch to root user, open up CPAN shell, go to run 'install Bundle::CPAN' and, well...
$ su root Password: # perl -MCPAN -e shell Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v1.7602) ReadLine support available (try 'install Bundle::CPAN') cpan> install Bundle::CPAN CPAN: Storable loaded ok Going to read /root/.cpan/Metadata Warning: Cannot install Bundle::CPAN, don't know what it is. Try the command i /Bundle::CPAN/ to find objects with matching identifiers. cpan> i /Bundle::CPAN/ No objects found of any type for argument /Bundle::CPAN/ cpan>
Huh? Can anyone 'splain why this happened...? I have looked at the Metadata file and it looks ok, but then again I don't know what a *bad* Metadata file would look like. If anyone could shed some light on this I'd really appreciate this!

Replies are listed 'Best First'.
Re: Cannot install CPAN (or any other modules) as root user!!!
by ikegami (Patriarch) on Jul 14, 2009 at 17:53 UTC
    Instead of running the entire process as root, why don't you configure cpan to install as root using one of the following:
    o conf make_install_make_command 'su root -c make' o conf mbuild_install_build_command 'su root -c ./Build'
    o conf make_install_make_command 'sudo make' o conf mbuild_install_build_command 'sudo ./Build'
    o conf make_install_make_command 'sudo -u root make' o conf mbuild_install_build_command 'sudo -u root ./Build'

    It won't solve your problem so much as bypass it. And it's safer as a bonus!

    Note that the change isn't permanent unless you follow up using the following:

    o conf commit

    Update: Added instructions to use su/sudo with distros that use Module::Build (Build.PL).
    Update: Fixed to use correct configuration option name, as per afauno's reply.

      I found my problem... as my user CPAN is pointing as a Metadata file path different than root user is. I've been staring at this terminal screen for too long. I will implement your method so when I forget to switch users I'll be OK. In fact, looks like I won't have to remember to switch users.

      Thanks for the idea, it never occurred to me...

      Althought for the Module::Build part I suppose you meant mbuild_install_build_command instead of mbuild_arg