Configuring CPAN.pm to use sudo to install

For security, I like to run CPAN.pm as a normal user so building & testing modules are all performed as a user rather than root, but of course the final installation needs to be done as root so that files can be copied to paths not writeable by normal users.

I always forget the options I need, so for my future reference as well as anyone else who finds it useful:

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

That means that the actual installation gets run via sudo, with everything else just being done as the user you started the CPAN client as.

(Of course, these days, you could also use cpanm (cpanminus) with its –sudo option…)

2 thoughts on “Configuring CPAN.pm to use sudo to install”

  1. I do use cpanm these days – it’s far faster and easier :)

    To make cpanm use sudo as appropriate, and also use my mirror, I have the following in my .profile:

    
    export PERL_CPANM_OPT="--sudo --mirror http://cpan.mirrors.uk2.net/"
    

Comments are closed.