Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is there a way to install modules from CPAN without resorting to sudo?

(And without perlbrew, please.)

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You can configure cpan to install modules outside of the system default path. Point it to some place under your home directory and you shouldn't need to call it with sudo to install modules.

The o command in the cpan interactive shell lets you change options for cpan and the makepl_arg option changes the options that are passed to the perl Makefile.pl call that CPAN makes to build the Makefile for the module.

If you wanted to change the install path to ~/lib/perl5 you'd do:

mkdir -p ~/lib/perl5
perl -MCPAN -e shell

And from the CPAN shell:

cpan> o conf makepl_arg 'PREFIX=~/lib/perl5'
cpan> install MyModule

To use modules installed in this location you'll need to add this path to your PERL5LIB environment variable. For bash do:

export PER5LIB=~/lib/perl5

Or whatever environment variable setting syntax is required by your shell of choice.

There's a nice discussion of customizing CPAN for a single user here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.