Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid sudo-ing when installing Perl modules with 'cpan'?

Tags:

sudo

perl

cpan

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?

like image 415
AmbroseChapel Avatar asked Jan 09 '10 01:01

AmbroseChapel


4 Answers

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/
like image 175
Telemachus Avatar answered Oct 03 '22 06:10

Telemachus


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
like image 29
Greg Bacon Avatar answered Oct 03 '22 06:10

Greg Bacon


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, :)

like image 25
brian d foy Avatar answered Oct 03 '22 06:10

brian d foy


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.)

like image 22
Sean McMillan Avatar answered Oct 03 '22 08:10

Sean McMillan