If you've come across any software that requires Perl modules, you might have found yourself pulling out your hair, trying to figure out how to install those modules. You've tried downloading the source, only to find one dependency issue or another. You've searched Synaptic or gnome-packagekit high and low to come up empty handed.
What you may not know is there is a tool specifically designed to help you install Perl modules. The tool? CPAN. CPAN is the Comprehensive Perl Archive Network and contains a vast assortment of software, used by and with Perl, and makes for easy installation. Problem is, most people don't know about CPAN or how to use it.
In this article I will introduce you to the CPAN tool and how it can be used to help you get all the Perl modules you need installed. NOTE: There will be times when CPAN has trouble installing modules. In those cases, the best bet is to download the source and read through the README file for better instructions. Generally speaking though, you should be able to get the majority of modules installed with this tool.
If you have Perl installed on your machine, you have CPAN. You can test this out by issuing the command cpan from the command line. If you get the dreaded command not found make sure you have:
installed. If one (or more) is missing, mark them for installation and then try the command again. When you have successfully reached the CPAN console your prompt will look like:
When you see that, you're ready to rock.
The basic structure of cpan is simple. Once you're at the command prompt you would issue a command similar to:
Where MODULE::NAME is the actual name of the module.
But when you first run CPAN the system will ask you a few easy questions. CPAN will want to check for a network connection and so on (hit Enter to accept all of the defaults).
When you have first reached the CPAN prompt you might want to first install a couple of bundle packs that contain numerous modules. The very first install command you will enter is:
The above command will install numerous modules, but it might also come up with some errors. Any time you receive an error in CPAN it will report the error to you in the console. Often times the error will point you in a direction that will help to resolve an issue. For example, running install Bundle::CPAN on a fresh install gives me:
Warning: prerequisite Compress::Raw::Zlib 2.024 not found. We have 2.008.
Writing Makefile for IO::Compress
Could not read '/root/.cpan/build/IO-Compress-2.024-1nwcFW/META.yml'. Falling back to other methods to determine prerequisites
---- Unsatisfied dependencies detected during ----
---- PMQS/IO-Compress-2.024.tar.gz ----
Shall I follow them and prepend them to the queue
of modules we are processing right now? [yes]
So, as you can see, CPAN is intelligently resolving your dependency issues for you. In a large install like Bundle:CPAN this can take quite some time.
How to know which module?
If you are trying to install a piece of software on Linux usually you are given a solid roadmap in either the README or INSTALL file with the source. Within that file will be listed any/all Perl modules necessary to meet the installation requirements. And now, with the help of CPAN, you can install them.
Believe it or not, using CPAN is a simple process. From this easy to use console you can install all of the Perl modules you need. Of course, there is much more to CPAN than this. To find out how much more enter h at the CPAN console for the help file.Advertisement
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.