Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Local CPAN settings

by Tanktalus (Canon)
on Feb 20, 2007 at 03:25 UTC ( [id://601013]=perlmeditation: print w/replies, xml ) Need Help??

Since the CPAN on my system normally needs root access to install, I normally run cpan as root (probably a bad idea, but I need CPAN.pm to ask for my sudo location before I start running it as my own user). The distress this causes is a meditation for another time. Here I would like to talk about setting up a local CPAN settings without much work. The purpose? I just want to fetch some modules so I can put them up on my web host. How to install them without having shell access has been discussed before, so I'm going to search for that, and then do what I need to get them installed privately.

My first attempt was a naive "if I run as my own user, it should just detect I've not done this before and ask me all the questions again." While that is mildly annoying, it's just a one-time setup, and shouldn't be that big of a deal. Unfortunately, that doesn't work. It couldn't mkdir /root/.cpan - permission denied. A bit of digging, and I eventually found that CPAN sets its configuration in /usr/lib/perl5/5.8.8/CPAN/Config.pm. YMMV - but it's definitely a global path. A bit odd... Anyway, that file says that you can override it locally (no interactive setup!) by creating ~/.cpan/CPAN/MyConfig.pm, and putting your changes there. That's a bit awkward, so I put this in my version:

use User::pwent; my $root = getpw(0)->dir(); my $home = getpw($<)->dir(); for (keys %{$CPAN::Config}) { $CPAN::Config->{$_} =~ s:^\Q$root:$home:; } 1; __END__
Now, most likely, if I try to "o conf make_arg -j5" or something, it'll do something strange. Like completely override my file, or crash trying to figure it out, or attempt to overwrite the global CPAN::Config. I'm not sure which. So I don't plan on doing that.

Now, if cpan just figured out that the configuration was bogus and simply reinitialised itself, that would have been a step forward. But, until then ... hopefully this helps someone.

Replies are listed 'Best First'.
Re: Local CPAN settings
by rinceWind (Monsignor) on Feb 20, 2007 at 06:56 UTC

    Good meditation; I've been there.

    As you have observed, some versions of CPAN.pm install config information to a CPAN::Config in everybody's @INC path, in such a way as to prevent non-root users from using CPAN.pm. When this happens, I have removed (or simply moved out of the way) Config.pm, and rerun the configuration dialogue as a non-root user.

    As an aside, I have a standard technique for dealing with CPAN on Unix systems. The first stage might be to upgrade the perl if the version is older than I am comfortable with. Otherwise, in most instances, the version of CPAN.pm that the installed Perl ships with is a bit old.

    I install curl, ncftp and lynx, as these are tools that CPAN.pm will be asking for. And I install and configure sudo of course if it's not there.

    As root, I upgrade CPAN.pm to the latest, going through all the configuration questions installing CPAN and leaving the CPAN shell. Then, as my non-root user I run cpan and go through the questions again, except this time, there are more of them, including questions about make install and ./build install. To these questions I use the sudo form of the command. Once this dialogue is complete, I can install Bundle::CPAN and any other modules I want, painlessly.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      When you say, use the sudo form of the command, can you give an example? Just trying to understand what you are doing.

        OK, I'll paste some excerpts from the dialogue from cpan "o conf init".

        Do you want to use a different make command for 'make install'? Cautious people will probably prefer: su root -c make or sudo make or /path1/to/sudo -u admin_account /path2/to/make or some such. Your choice: [sudo make] ... Do you want to use a different command for './Build install'? Sudo users will probably prefer: su root -c ./Build or sudo ./Build or /path1/to/sudo -u admin_account ./Build or some such. Your choice: [sudo ./Build]

        --

        Oh Lord, won’t you burn me a Knoppix CD ?
        My friends all rate Windows, I must disagree.
        Your powers of persuasion will set them all free,
        So oh Lord, won’t you burn me a Knoppix CD ?
        (Missquoting Janis Joplin)

Re: Local CPAN settings
by j3 (Friar) on Feb 20, 2007 at 19:33 UTC

    Off-topic, but just curious Tanktalus: why not just make a ~/perllib directory on the webserver then manually download, build, and install the modules by-hand?

      No shell access. Kind of a bummer, but not a serious barrier when I can install via a CGI script ;-). Sure, I could download at the webserver via that same script, but downloading at home first means I can better control the details. I can even use private patches if I desire.
Re: Local CPAN settings
by Anonymous Monk on Mar 02, 2007 at 09:56 UTC
    Ummmmmm I faced a similar problem....couldnt get around it... I dont have root access...so cant install lynx in my system.. or anything else for that matter...I do have access to shell but dunno what to do with that...since everything needs root access...I just installed just the required modules manually... it was a pain..but I got there....;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://601013]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-29 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found