Perl: How to Install Perl Modules in few quick steps

Perl enjoys a very ubiquitous presence in the scripting language world, it comes as a default installation in almost all the *IX platforms. One of the reasons that is so extensible through the use of . also has been ported to Windows by ActiveState, making it easily downloadable and installable product on Windows too.

With , the advantage is that code can be shared in the community as easily  as  it is written. The code is either written in the form of script or the library files which are termed to be ‘packages’ or ‘’. The should be installed on the system to use them. CPAN, which stands for Comprehensive Perl Archive Network, is a very popular place for the community to share/distribute the code and hosts the largest collection of freely distributable code and documentation.

Another popular module is for Windows. stands Perl Package Manager developed by ActiveState for easy distribution of Windows based through their network. Most of the libraries or are already written and shared on network, it is often a best practice to check if there is already a perl module written for the intentional needs of the yet to be written script. After all it is better to reuse the code to save time and efforts and concentrate on the actual need and nevertheless also follow the principle of ‘Do not Reinvent the Wheel’. :-)

This article attempts to showcase few easy ways of installing using and . Although there are definitely many other ways which goes well in synchronization with the idiom ‘There is more than one way to do it‘. :-)

Before attempting for the installation of the module, it is better to check whether the module is already  installed. Most common way, for example, to check for the existence of ‘Config::IniFiles’ module, is to :

[nikhil@snerd ~]$ -e "use Config::IniFiles; print version: $Config::IniFiles::VERSION"

version: 2.38

[nikhil@snerd ~]$ 

 

In this case it has been installed as it prints the version, but if you get an error like this:

[nikhil@tnerd ~]$ -e 'use Config::Ini;'

Can't locate Config/Ini. in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8/i386-linux-thread-multi  /usr/lib/perl5/5.8.8 .) at -e line 1. BEGIN failed--compilation aborted at -e line 1.

[nikhil@tnerd ~]$


Then, the module has not been installed yet.

Most of the steps described below are common to Unix and Windows, but have been explicitly described if the step is specific to Windows or Unix wherever necessary.

To install module through the network using the module

PS: Note that, besides the name of the network there is a module named ‘CPAN‘, so don’t be confused.

$ sudo -M -e 'install Config::IniFiles'

CPAN module has the code to download the latest stable version of module from the repository online. It does the sanity checks for compatibility with the installed version of the , automatically resolves any package dependencies and then builds the preparing them for the installation and finally installs the in the library directory.

Here in most cases, it is assumed that you are either an administrator/super-user or have a write privileges to your   installation library, allowing you to install the .

If you are a normal user and do not have a write access to your system-wide installation, you could use your home directory to serve as the library location for your scripts. Yes, ordinary users can still install and use from their home directory for their development works. However, the script working for the developer may not be usable by others if the script happens to depend on a certain module which is only installed in his home directory but not system-wide.

Well, it’s not a smart move to ask the users to install the module in their home directories. It is advisable to contact the system support to get the scripts installed on the machine. I am sure, no System administrator would be hesitant to install the module on the machine given its impact value for many users.

To setup library folder and install module as normal user under one’s home directory, follow the below procedure:

[nikhil@tnerd nikhil]$ echo $0 -bash

[nikhil@tnerd nikhil]$ export PERL5LIB=/nikhil/myperl/lib/perl5/site_perl/5.8.8 

[nikhil@tnerd nikhil]$ mkdir $HOME/myperl

[nikhil@tnerd nikhil]$ -V | grep myperl ="/nikhil/myperl" /nikhil/myperl

[nikhil@tnerd ~]$ -MCPAN -e shell shell

-- exploration and installation (v1.7602) ReadLine support available (try 'install Bundle::')

> o conf makepl_arg makepl_arg

> o conf makepl_arg PREFIX=/nikhil/myperl makepl_arg PREFIX=/nikhil/myperl

> o conf commit commit: wrote /nikhil/.//MyConfig.

The above sets and saves the configuration to install the in the home directory.

Now proceed to install the module. Voila, you will be thrilled to see the module getting installed under your home directory.

> install Config::IniFiles

... ...

/usr/bin/make test -- OK

Running make install

Manifying blib/man3/Config::IniFiles.3pm

Installing /nikhil/myperl/lib/perl5/site_perl/5.8.8/Config/IniFiles.

Installing /nikhil/myperl/share/man/man3/Config::IniFiles.3pm

Writing /nikhil/myperl/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/ Config/IniFiles/.packlist

Appending installation info to /nikhil/myperl/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod

/usr/bin/make install -- OK

>


Now that the perl module is installed in the home directory, to use it from the location, one must either

[nikhil@tnerd ~]$ export =/nikhil/myperl/lib/perl5/site_perl/5.8.8

[nikhil@tnerd ~]$ -e 'use Config::IniFiles; print $Config::IniFileERSION, "\n";'

2.38

[nikhil@tnerd ~]$ 

or

[nikhil@tnerd ~]$ cat /tmp/test-module.

use lib '/nikhil/myperl/lib/perl5/site_perl/5.8.8';

use Config::IniFiles;

print $Config::IniFiles::VERSION,"\n";

[nikhil@tnerd ~]$ /tmp/test-module.

2.38

[nikhil@tnerd ~]$


In some rare cases, it is seen that there are some problematic whose installation fail with this method. It is then best suggested to download the module directly from search.cpan.org and build manually.

Follow the below steps for manual install, after downloading the package from search..org: This works on Unix/Linux platforms, as it requires the make utility. For Windows, nmake utility is available to work on the Makefile(s).

  1. Extract the compressed module package using tar/zip utilities
  2. Run Makefile. (sometimes there is a Makefile., note the case)
  3. make
  4. make test
  5. sudo make install

Manual installation of the module as a normal user under home directory:

  1. Extract the compressed module package using tar/zip
  2. Makefile. PREFIX=/nikhil/myperl
  3. make
  4. make test
  5. make install

To install module on Windows through , is aware of selecting the ActiveState online repository and verifies the metadata repository to check the availability and compatibility of the module on the Windows platform.

C:\> -5.8.8\bin\ install Config::IniFiles

Downloading ActiveState Package Repository packlist...not modified

Downloading Config-IniFiles-2.38...done

Unpacking Config-IniFiles-2.38...done

Generating HTML for Config-IniFiles-2.38...done

Updating files in site area...done

2 files installed


Most of the general module are present on Windows and incase you come across any specific module that is not yet been ported to Windows, you can write to ActiveState developers asking for it. Chances are that ActiveState developers might have already attempted to port the module to Windows platform but could not due to technical reasons.

The notable key advantage with both the and is that they automatically resolve the dependency packages and install the dependent packages. Lets say, module Foo::f is requested to be installed and Foo::f depends on Bar::b before its installation, and Bar::b is dependent on Cat::c and Dog::d, then the Cat::c, Dog::d and Bar::b are also installed along with Foo::f.

This not only significantly saves time searching and recursive installation of the dependent but also help in effective and organized package management. This is also the same model that you see these days with the popular package managers like apt or yum for Linux packages.

Hope the steps were easy to understand and follow. Do let us know if there is an easier way of doing this.

Tags: , , , , , ,

Share the word!

Delicious it! Digg It! Submit to reddit Share on Technorati! Stumble it Twitter It
Get the latest in Technology and Trends

Subscribe via Email

Subscribe to TNerd RSS

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading ... Loading ...
Rate this article:


Related Posts:

  • TOP 10 Freenode Channels Offering Real-Time Help on Open Source Technologies!
  • How to Upgrade Old Firefox extensions to be compatible with Firefox 3
  • Google Personalized homepage offers Tabs
  • Use Google Gadgets on the Desktop without installing Google Desktop!
  • How to uninstall or remove KDE and restore Gnome Desktop Manager in Ubuntu

  • Popular Posts:

    Free online movies download free movies best facebook applications convert .flv India GPS iPhone India

    If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

    Comments

    No comments yet.

    Leave a comment

    (required)

    (required)


    Spam protection by WP Captcha-Free