tags:

views:

298

answers:

3

I have installed Perl from source into /usr/local, and adjusted my path accordingly, following brian d foy's suggestion here.

I'm sure I'm missing something, but, now I'm trying to install stuff with the 'cpan' command and it's failing because it can't write to /usr/local. I have to use sudo, which feels wrong to me. Should CPAN stuff go to another location? Is it normal to have to use sudo?

+5  A: 

The /usr/local tree is protected. It's perfectly normal to use sudo to install software there.

Installing to a separate library location is a frequently-asked question. See "How do I keep my own module/library directory?" in section 8.

Key excerpt:

You can set this in your CPAN.pm configuration so modules automatically install in your private library directory when you use the CPAN.pm shell:

% cpan  
cpan> o conf makepl_arg INSTALL_BASE=/mydir/perl  
cpan> o conf commit

For Build.PL-based distributions, use the --install_base option:

perl Build.PL --install_base /mydir/perl

You can configure CPAN.pm to automatically use this option too:

% cpan  
cpan> o conf mbuild_arg "--install_base /mydir/perl"  
cpan> o conf commit
Greg Bacon
I think he's already doing this. The advice in the FAQ is insufficient for this. There's a mbuild_install_build_command and a make_install_make_command option where you can set sudo as a command to use in the install step.
brian d foy
+7  A: 

If it really bothers you to use sudo, you can use local::lib and install modules in your home directory - where you don't need super-user privileges.

That said, it shouldn't bother you to use sudo. There's nothing necessarily wrong with it. As Gbacon says, you need it if you want to install in /usr/local because /usr/local is shared by all users on the system (and so it's permissions reflect that):

    telemachus ~ $ ls -ld /usr/local/
    drwxr-xr-x 17 root wheel 578 Jan  8 20:00 /usr/local/
Telemachus
The problem with local::lib is maintaining distinct perls at the same time. If you want to isolate the installations completely as I suggest, you don't want to install the modules for the different perls in the same directory.
brian d foy
+6  A: 

The /usr/local directory shouldn't be writeable by a normal user, but the unix setup has many features to handle this.

In my advice, I suggested setting up /usr/local/perls. You can give that directory whatever permissions you like. Don't apply any permissions to more directories than you need.

I suggest setting up a perl group, adding yourself to that group, and making the perl library directories group writeable. Once setup, you don't have to sudo because you have group permissions.

Beyond that, you can adjust your CPAN.pm config to use sudo during the install phases. Check out the make_install_make_command and mbuild_install_build_command commands in the docs. Just search for "sudo" and you'll find them.

Good luck, :)

brian d foy