Is there a way to install modules from CPAN without resorting to sudo?
(And without perlbrew, please.)
Best Answer
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.
Open the /Applications/Utilities/Terminal.app and you have a unix prompt.
Both perl and cpan ship with OS X so you have nothing to install unless you want a different version of them than ships with your particular version and build of OS X.
Air:~ me$ cpan Perl6::Say
Sorry, we have to rerun the configuration dialog for CPAN.pm due to
some missing parameters... Will write to
<</Users/me/.cpan/CPAN/MyConfig.pm>>
Best Answer
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 withsudo
to install modules.The
o
command in thecpan
interactive shell lets you change options forcpan
and themakepl_arg
option changes the options that are passed to theperl 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:And from the CPAN shell:
To use modules installed in this location you'll need to add this path to your
PERL5LIB
environment variable. For bash do: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.