I had to install XML::Parser CPAN module to parse some of the xml files. But I was getting “requires expat.h”Read more
If you are working on Perl and you need to work on modules which is listed in CPAN. You may need to download it, install it and use it in your box.
For that you need to know how to install Perl modules. This article will show you simple steps to download and install Perl modules in Linux box. I know it’s not the new topic for Perl chapter but I wrote it for our standalone repository on Perl and moreover, all these method with examples and pitfalls are not listed at many places. So, I think it will be worthy for our viewers and Perl mongers 😀
Method 1 using cpan shell(It has advantage over manual installation. Read Note section at the bottom)
1. perl -MCPAN -e shell
cpan> install HTML::Template
2. perl -MCPAN -e ‘install HTML::Template’
3. cpan -i MIME::Lite
Method 2 Manual module installation
if you’re having problems installing with CPAN. If you’re on the command line, you can use something like wget to grab the file. Next you’ll want to unzip it with something like:
tar -zxvf HTML-Template-2.8.tar.gz
In case above command doesn’t work for you, try this
gzip -d XML-Parser-2.36.tar.gz
tar -xvf XML-Parser-2.36.tar
This will unzip the module into a directory, then you can move in and poke around – look for the README or INSTALL files.
In most cases, installing a module by hand is still pretty easy, though (although not as easy as CPAN). Once you’ve switched into the base directory for the module, you should be able to get it installed by typing:(I assume you are on Linux box)
1. perl Makefile.PL
3. make test
4. make install
If everything shows fine then That’s it. You are now ready to rock and roll with newly installed Perl modues 😀
But what if cpan command doesn’t work for method 1?
1. Check first if cpan command works in your box
cpan: Command not found.
If you get the above result means you need to install cpan module to work from CPAN otherwise, you have cpan installed in your system and you can skim next steps 😀
2. yum install perl-CPAN
3. after successful download and installation. Type cpan for the first time use
and type o conf commit on cpan prompt
then type quit on cpan prompt
You are done! Now Method 1 will work without fail.
Note: If any CPAN module is dependent on the several other modules. CPAN automatically resolves the dependencies and installs other dependent modules.
cpanm module is more advanced for doing all these without hassle. If possible give it a try.
As it was commented through Facebook by one of our readers, so I thought to better update this article with his comments.
# Install cpanminus (once).
curl -L http://cpanmin.us | perl – –self-upgrade or
# Install your CPAN modules.