Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

(And without perlbrew, please.)

share|improve this question
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 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

Your Answer


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.