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.


In reply to Local CPAN settings by Tanktalus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.