10

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?

Community
  • 1
  • 1
AmbroseChapel
  • 11,957
  • 7
  • 46
  • 68

4 Answers4

11

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 its permissions reflect that):

    telemachus ~ $ ls -ld /usr/local/
    drwxr-xr-x 17 root wheel 578 Jan  8 20:00 /usr/local/
Telemachus
  • 19,459
  • 7
  • 57
  • 79
  • 1
    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 Jan 09 '10 at 10:11
9

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
  • 134,834
  • 32
  • 188
  • 245
  • 1
    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 Jan 09 '10 at 10:04
9

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 configuration to use sudo during the install phases. Check out the make_install_make_command and mbuild_install_build_command commands in the documentation. Just search for "sudo", and you'll find them.

Good luck, :)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
brian d foy
  • 129,424
  • 31
  • 207
  • 592
7

In your CPAN shell, configure it to run the make and build steps under sudo:

o conf make_install_make_command 'sudo make'
o conf mbuild_install_build_command 'sudo ./Build'
o conf commit
quit

(I found these here -- I'm no CPAN guru.)

Sean McMillan
  • 10,058
  • 6
  • 55
  • 65