Dual-license your content for inclusion in The Perl 5 Wiki using this HOWTO, or join us for a chat on irc.freenode.net#PerlNet.

Installing Perl Modules on Linux

From PerlNet

Jump to: navigation, search

Contents

Overview

Linux invariably comes with a system version of Perl. Whilst this may be suitable for 'casual' use there are issues for serious development and use.

  1. The version of Perl you need may be unavailable in the package system of your current Linux version
  2. The specific CPAN modules you need will often not be packaged for your system

Maintain a development Perl

The currently recommended solution:

  1. maintain the system supplied Perl "as is" so that it can be used by any packages that need it.
  2. Install additional Perl distributions as needed. This can be achieved by either:
    1. Using APP::perlbrew (you can install in your home directory or in some accessible location such as /usr/local/)NB The App::cpanminus is also helpful
    2. Installing by hand
    3. Rolling your own packages. This is recommended if you need to deploy to multiple systems (some of the notes below may help, see also PAR::Packer)



Maintaining system supplied Perl

If you do need to add CPAN modules to your system supplied Perl then using the package management tools included with your Linux distribution is nearly always the recommended solution in preference to installing via the CPAN shell.

Package tools help ensure that:

  • C library and other non-CPAN dependencies are resolved correctly
  • existing packages that rely on CPAN modules will not install conflicting versions
  • there is a single tool for admins to check what packages have been installed on a system

Most distributions will already include packages for popular CPAN modules. The information below provides some pointers on how to create packages for newer module versions (or ones that aren't yet packaged in your Linux distribution).

APT package management (i.e. Debian, Knoppix, Ubuntu, ..)

Building an apt package from CPAN is usually as simple as:

      dh-make-perl --build --cpan Example::Module

You can change --build to --install if you want to install the module after the package is built.

If you don't have dh-make-perl installed, you can do so using:

      apt-get install dh-make-perl

The package file created will have a ".deb" extension, for example:

      libwww-perl_5.805-1_all.deb

To install the generated .deb package use:

      dpkg -i packagename.deb

For more information see Building Debian packages of Perl modules.

Portage package management (i.e. Gentoo)

To find or create a Gentoo package for a CPAN module, use:

      g-cpan -i <Example::Module>

If a package isn't found, g-cpan will fetch the current CPAN version of the requested module and create a Gentoo package, then install the package into the dependency tree.

For more information see the g-cpan Guide in the Gentoo documentation.

RPM package management (i.e. Redhat, Fedora, CentOS, Yellow Dog. ...)

To create an RPM package for a CPAN module, use:

     cpan2rpm Example::Module /tmp/Example-Module.tar.gz

You may find that cpan2rpm occasionally needs a bit of a helping hand; for example, you may need to run with debug options to allow terminal interaction during the build process. In general this program does a great job of spitting out an RPM from an arbitrary CPAN module.

For more information visit the cpan2rpm project home page or refer to the cpan2pm man page.


This information was initially culled from the Melbourne Perl Mongers mailing list based on comments by Paul Fenwick, Matthew Robertson, Daniel Pittman, and others. Updated after discussions at the Melbourne Perl Mongers meeting March 2011

Personal tools