Charles Engelke's Blog

April 13, 2007

Installing Perl Modules without root

Filed under: How To — Charles Engelke @ 2:00 am

I just got this working, and I know I’m going to want to know how to do this a year or two down the road, and I’ll have forgotten by then. Hence, this blog entry.

You install prebuilt Perl modules in Windows using ActiveState’s Perl Package Manager (ppm). If you’ve got a full build environment, you can use the CPAN module instead.

Under Unix/Linux, you just use CPAN, because you generally have a full build environment. But Unix/Linux is a multi-user, secure environment, and unless you are the superuser, you can’t install modules normally with CPAN. That’s because they need to get installed to system directories and you can’t write to them.

But you can create your own personal libraries, and configure CPAN to use them.

1 – Create subdirectories under your home directory for the libraries. I think you can just create the main directory you need, but I created several others to be sure:

$ mkdir ~/myperl
$ mkdir ~/myperl/lib
$ mkdir ~/myperl/man
$ mkdir ~/myperl/man/man1
$ mkdir ~/myperl/man/man3

2 – Configure CPAN to install to your local directories:

$ cpan
cpan> o conf makepl_args PREFIX=”~/myperl”
cpan> o conf commit
cpan> quit

3 – Set the PERL5LIB environment variable to point to the library directory you are using:

$ PERL5LIB=~/myperl/lib
$ export PERL5LIB

Now you can use CPAN as a normal user (but it will only install modules for you to use). Remember that the CPAN settings are saved, but you’ll have to set the PERL5LIB variable each time you log in, or else save it in your .bash_profile or .bashrc initialization file. I don’t use bash much, so I’ll probably have to look this up if I want to do it.

Updated: Laurie tried this, and found some issues. I fixed the main one above.

This is just about right, but the first line of the configuration in step 2 should be:

o conf makepl_arg "PREFIX=~/myperl"

And this still didn’t work for me, so I had to use the longer version:

o conf makepl_arg "LIB=~/myperl/lib \
INSTALLMAN1DIR=~/myperl/man/man1 \

Create a free website or blog at


Get every new post delivered to your Inbox.

Join 182 other followers