View Full Version : Installing Perl modules with CPAN

02-05-2004, 04:03 PM
There have been a lot of questions about how to install or update Perl modules with the CPAN interface, I decided to write up the instructions on doing it. If anyone wants to follow along with them (and be a guinea pig :D ) then here they are. Give me feedback and when its ready I'll put them up on my site:

Installing Perl Modules on Westhost.

Perl makes a lot of use of library modules, which can be installed and updated separately from the Perl program itself. These modules are normally installed using CPAN (itself a Perl module) which is used to automate the process of connecting to CPAN server and downloading, make'ing and installing the modules. On most servers, this is done as the root user, because a base Perl installation is normally owned by root. However on Westhost, we don't have root privileges so we need to take some extra steps to install the modules elsewhere. What follows is a method of doing that.
CPAN stands for the Comprehensive Perl Archive Network and more information on it can be found at http://www.cpan.org/

Before starting you need to make sure that you have the GCC Compiler Collection installed, this is needed and without it Perl will still run but building of the modules will probably (but not certainly) fail. And remember, you are messing with the server system, if you're not comfortable with doing this, don't!

Because we don't have root privileges to install or update the Perl modules, we need to install the modules elsewhere, in a directory that we have access to. In addition to installing the modules, we also need to tell Perl where the extra libraries are installed so that Perl can find them when running. We are going to create a directory '/perl5lib' and use that for the installations. You can call the directory what you want and install it wherever you like as long as you have write permission for it. In the following I will assume it is '/perl5lib'.

First, you need to start up the CPAN modules, this is done by typing:
$ perl -MCPAN -e shell
or, alternatively:
$ cpan

The cpan shell will then realize that this is the first time it has been called and ask if you want to do a manual configuration. You do, so answer yes. If you have already run cpan before and configured it, see below for modifying the configuration.
All the questions have default answers and you can just hit enter to accept the default, until you reach a question like:
"Parameters for 'perl Makefile.PL' command?"
Here you want to enter the following:
PREFIX=/perl5lib LIB=/perl5lib/lib INSTALLMAN1DIR=/perl5lib/man1 INSTALLMAN3DIR=/perl5lib/man3

Accept the defaults for the next few questions until you are asked for your favorite mirrors. You want to choose mirrors in North America/United States and then select some mirrors.

Once that is done, continue with the defaults to any questions until you are back at the cpan prompt and then type quit.

If you have run cpan before and configured it and need to change the configuration, then do this:
$ cpan
cpan>o conf
cpan>o conf makepl_arg PREFIX=/perl5lib LIB=/perl5lib/lib INSTALLMAN1DIR=/perl5lib/man1 INSTALLMAN3DIR=/perl5lib/man3
cpan> quit

So, now we have told CPAN about our new directory, we need to tell the system about it as well. For this you need to enter the following line in your .bashrc file:
export PERL5LIB=/perl5lib/lib

Save the file, and log off the SSH session. Then log back in again.

Now we are ready to try installing a module. A good test of the system is to install an update for the CPAN modules itself. Start cpan
$ cpan
cpan> install Bundle::CPAN

There will then be a flurry of activity, possibly a few warnings until you get a question about 'unsatisfied dependencies'. Answer 'yes' to have them installed as well (the dependencies might vary, but on my system CPAN also installed Digest::MD5 and File::Spec). There will be a lot more text scrolling by until you finally get a success message and you are returned to the prompt.
Next, reload cpan with:
cpan>reload cpan
and, assuming that was successful, you should be able to install the modules that you need.


02-05-2004, 06:36 PM
Thank You, Thank You, Thank You, Thank You, Thank You, Thank You, :)

I have been struggleing with all this and just did not know the right questions to ask.

I ran the cpan so well now have to go back and configure it. I do have a couple comments. I think I know ways on how to this or at least check int the forums to find how to edit a file using pico? in SSH but if you are doing this as a tutorial pehaps a link to that explenation would be good in that area.
So, now we have told CPAN about our new directory, we need to tell the system about it as well. For this you need to enter the following line in your .bashrc file:
export PERL5LIB=/perl5lib/lib

Save the file, and log off the SSH session. Then log back in again.

The next question is that I have installed Bundle::CPAN (with out the special config and setup) and I belive it did update some stuff but that maybe I could use the .bashrc file to tell the system where they are. I well try to look and see if I can find an example of what I am talking about.

Thank you again Jalal for this. I can't wait to try it out. :D

02-06-2004, 03:02 AM
I do have a couple comments. I think I know ways on how to this or at least check int the forums to find how to edit a file using pico? in SSH but if you are doing this as a tutorial pehaps a link to that explenation would be good in that area.

Pico is pretty simple, it shouldn't take too long to figure out. VI is much better though.

Thank you again Jalal for this. I can't wait to try it out. :D

Let me know what doesn't work...

02-06-2004, 09:58 AM
Hi Jalal,

Decided to try the reconfigure part since I had already installed CPAN

I went in to SSH and started up CPAN
I then typed the first command
cpan>o conf

I got
CPAN::Config options from /usr/local/perl/lib/5.6.0/Config.pm:
It then list the configuration of each thing these are a few of the paths it listed.

build_dir /home/username/.cpan/build
cpan_home /home/username/.cpan
keep_source_where /home/username/.cpan/sources

the others are for like ftp, shell, tar, zip... I think those do not matter are set the same no matter what.

Ok the reason I listed this is when I check permissions and such there are two dirctories concerning perl


The first one seems to be owned by root for the most part and has the Config.pm

The second one seems to be owned by user and does not have the Config.pm. I can change stuff in that directory i.e the permission on things. I can't do that in the first dirctory.

I went ahead and stopped in the process to ask if perhaps I should use this second directory instead of setting up another one. The only thing drawback I can see it that the man and lib dirctories are back up the line at /usr/local/perl the premission on each are
drwxrwxr-t 4 root vuser 4096 Jan 26 18:09 lib
drwxrwxr-t 4 username vuser 4096 Jan 26 18:09 man

It may just be easier to start clean but didn't want to get a bunch of duplicate directories and files all over the place. In the examples above I have used username where it is really my true username that I am logged in as.

02-06-2004, 10:38 AM
I would not try to mess with what is already installed on the server, for two reasons:
1. its hard to predict what is going to be writable and what isn't
2. westhost is going to overwrite a bunch of stuff if they ever do an upgrade.

As for duplicate files, yes, its a pity, but I think the directories listed in the PERL5LIB variable are read instead of the already installed ones.

I didn't mention it, but a clean way of starting up afresh is to delete the whole of /home/username/.cpan before running cpan, then you will get a fresh configuration.


02-06-2004, 11:19 AM
Supremely useful - just like everything else on your wonderful site. Excellent work, Tim! I just have a question (and something to contribute): as I said in my PM to you, I could not get DB_File installed - nor could I get BerkeleyDB - will using our own custom directory have any effect on this? Would it also allow one to install SpamAssassin (i.e. 2.63) with no problems? I know I could test this all myself, but I ask you so that you can clarify it - and post that clarification along with this tutorial (e.g. a "what this will do", "what this won't do" kind of thing). And now for my "contribution": deleting /home/username/.cpan just removes the "install files" of modules I have downloaded - it does not seem to reset my CPAN config... ;)

02-06-2004, 11:59 AM
Just a quick update of where I am on this. The first try is on hold for the moment. When I went to edit the .bashrc I was not able to since it is still owned by root. This is on one of my new accounts that I installed via my resellers account. Did some checking and some of my older accounts have already been switched and vuser has permission to edit .bashrc

So the bottom line is if for some reason you do not have access you need to call Support and ask them to change if for you. Just got off the phone with them and they said it would take about an hour for the system manager to get it done. I went ahead and had them change it on my other accounts while they where at it. So check the permissions on your .bashrc first and if vuser does not have access give the a call.

The support guy said that they are working on getting the default switched but till they do when new accounts are created root still owns .bashrc (at least with a resellers account)

02-06-2004, 12:11 PM

There is a way to do the .bashrc thing yourself, check it out: http://forums.westhost.com/phpBB2/viewtopic.php?p=8688#8688

02-06-2004, 12:31 PM
Thanks Fayez! I knew I had read something about it somewhere but could not find it or remember it. For the moment I well leave things as they are since they are changeing it but well keep that in mind for the future.

02-06-2004, 12:41 PM

If you remove the Config.pm from /usr/local/perl/lib/5.6.0/CPAN the it well give a fresh start. Make sure to leave the other files and directory there. If you delete the entire directory then you have to go get it back from one of your other accounts and upload it again... I know this :)

02-06-2004, 12:46 PM
And now for my "contribution": deleting /home/username/.cpan just removes the "install files" of modules I have downloaded - it does not seem to reset my CPAN config... ;)

Ah, yes... well in fact you can edit the config file directly, try editing:
look for the line that relates to makepl_args to change that setting.


02-06-2004, 01:02 PM
Hey Fayez
I just did a test install of BerkeleyDB, here is what I did:
log in to your account.

$ lynx http://www.sleepycat.com/download/index.shtml

select the "Version 4.2.52(GNU gzip/tar format)"
press 'd' to download it and then save it.
make a directory to unpack it in, I use ~/src/
change into the ~/src/ directory and type:

$ tar xzf /path/to/db-4.2.52.NC.tar.gz
$ cd db-4.2.52.NC/build_unix
$ ../dist/configure
$ make (now wait patiently...)
$ make install

You will need the 'sort' command for the above to work.

Of course, that doesn't mean that DB_File will install... although I noticed that there is already a version of DB_File installed (1.72) but there is a later version available (1.808).


02-06-2004, 01:39 PM
Ok Jalal I made it through!

All went pertty much as you described. I ended up using pico to modify the .basrc

For others who are not familiar with pico:
I typed pico at the SSH prompt and it opened up.
I then pressed ^r (^ means the control button)and it asked for the file and I entered .bashrc this opened up the file and I made the edit you suggested and pressed ^x it asked if I wanted to save the file and I answerd y and returned and then it asked for the filename to save as. I entered .bashrc and it asked if I wanted to overwrite the existing and I entered y. Works like a charm.

After I logged off and then back into SSH when I went into cpan it had some complaints about said I should consider installing Term::ReadKey. I ignored that and went ahead and did the install Bundle::CPAN.

The only thing that it did ask that you did not mention was something about libnet haveing been installed before I think that may be from one of my other attempts. Everything else went as you said but it did not ask about dependencies when it was finnished it did say it had the problems installing Digest::MD5 Compress::Zlib Bundle::libnet and Term::ReadKey and some problem during recursive bundle calls to Data::Dumper and Net::Cmd angain this may have been from my other attempts. I went ahead and did the reload of cpan and then quit it and went back in to it. The second entry into cpan went with not complaints or anything so I think I am all set now.

Just wanted to give you feedback on how it went with me. This was done on the account I had tried before so many of the diffrences may have been because of that.

The one question I have now is this.... Is my path to perl now diffrent for in scripts and when I call a module form a script do I have to somehow set the path to the /perl5lib? Or is that what the editing of the .bashrc file does for me?

02-06-2004, 02:57 PM
My understanding is that modules in the directories defined in the PERL5LIB variable will be found before those in the 'main' Perl installation.
This means that if you have updated Bundle::CPAN, you now have two copies of the CPAN module, the old one in /usr/local/perl/lib/... and new, updated version in $PERL5LIB (/perl5lib/lib). So, the new version will be found first and used.

I had the query about Term::ReadKey at first but that disappeared after update Bundle::CPAN.

Thanks for the feedback.

02-06-2004, 03:30 PM
Yes that seems to fit what is happening on the account that I did this on. It happens to also be the one that I was trying to get Gallery installed on. Gallery is now working. I can't remember what it's complaint was but it seems that with simply updateing Bundle::CPAN I now have the updated files it wanted.

Thanks again this is going to be a big step in the breakthrough to updateing the system. :)

02-06-2004, 07:48 PM
Alright, I am all set up with the new CPAN config and stuff. It's great - allowed me to install some stuff I could not before, e.g. a newer version of MakeMaker which SpamAssassin complains about. Managed to install SpamAssassin 2.63 as well - but not via CPAN (not a problem though). Before that, I used the instructions above (thanks Tim!) to get the Berkeley DB stuff installed - after which I was able to install DB_File - unfortunately, neither of which I did via CPAN (didn't work). Anyway, it wasn't so much of a problem - DB_File was a bit weird in that it complained about incompatible versions of libdb and db.h after doing a make test, but specifying PREFIX=, skipping make test and going straight to make install worked like a charm. Finally got SpamAssassin 2.63 working fully - except for spamd/spamc... Tim, this is your next challenge ;)

Thanks again.

04-03-2004, 10:24 PM
In your excellent "installing perl modules" directions you mention the need for "GCC". I don't seem to have that. Whenever I attempt to install a module, I get a "GCC not found" error. Any tips?

04-04-2004, 06:31 AM
You need to install the GNU Compiler collection using your Site Manager. It's on the SiteApplications/Tools section.

08-26-2005, 07:33 AM

Is it possible to install new version of DBI using method described by JALAL (install to /perl5lib)?

I'm trying to run the following string:
%> perl Makefile.PL PREFIX=/perl5lib LIB=/perl5lib/lib INSTALLMAN1DIR=/perl5lib/man1 INSTALLMAN3DIR=/perl5lib/man3

But it says:
Can't open PREFIX=/perl5lib: No such file or directory at Makefile.PL line 28.
Can't open LIB=/perl5lib/lib: No such file or directory at Makefile.PL line 28.
Can't open INSTALLMAN1DIR=/perl5lib/man1: No such file or directory at Makefile.PL line 28.
Can't open INSTALLMAN3DIR=/perl5lib/man3: No such file or directory at Makefile.PL line 28.

and make install is trying to install it to /usr/local/...

I'm wondering - is it possible at all to install new version of DBI?

11-03-2005, 10:02 AM

Thank you for this tutorial on installing with CPAN and Westhost. I have seemingly succesfuly followed all your directions above and was able to install the cpan bundle, but when I try to install the cpan module WWW-Mechanize it had errors in the test cycle.

In the effort of trying to understand this error, I am trying to look at what has been built so far, but I honestly do not understand where in the directory structure we are having CPAN install files to following your directions.

Where is


was I supposed to make these directories? are they linked under some other subdirectories somewhere (where?)

When I run a script requiring WWW-Mechanize I get the error
Can't locate WWW/Mechanize.pm in @INC (@INC contains: /perl5lib/lib/i686-linux /perl5lib/lib /usr/local/perl/lib/5.8.7/i686-linux /usr/local/perl/lib/5.8.7 /usr/local/perl/lib/site_perl/5.8.7/i686-linux /usr/local/perl/lib/site_perl/5.8.7 /usr/local/perl/lib/site_perl

I dont know why the cpan install of WWW-Mechanize had to fail, it failed during the test stage of making.

Has anyone had success in installing this module?

Thanks Jason