X BOL wishing you a very and Happy New year

Alternative content

  • Blogs
  • Perl *PIPERs
  • How to install Perl modules manually, using CPAN command, and other quick ways

How to install Perl modules manually, using CPAN command, and other quick ways

As a bioinformatics programmer, and crunchy data analyser you need to install several perl modules and dependencies. Installing Perl modules manually by resolving all the dependencies is  tedious and annoying process. Some of the packages like GD is the real pain.

However, Installing Perl modules using CPAN is a better solution, as it resolves all the dependencies automatically. In this article, let us review how to install Perl modules on Linux ( which is prefereced amonst bioinformatician) using both manual and CPAN method.

When a Perl module is not installed, application will display the following error message. In this example, XML::Parser Perl module is missing.

Can't locate XML/parser.pm in @INC (@INC contains:
/usr/lib/perl5/5.10.0/i386-linux-thread-multi
/usr/lib/perl5/5.10.0
/usr/local/lib/perl5/site_perl/5.10.0/i386-linux-thread-multi
/usr/local/lib/perl5/site_perl/5.10.0
/usr/lib/perl5/vendor_perl/5.10.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.10.0 /usr/lib/perl5/vendor_perl
/usr/lib/perl5/site_perl/5.10.0 .)

Manual Method of Perl Module Installation

  • Install Perl Modules Manually

This manual method is very useful when your computer or server is not connected to the Internet.

Download Perl module:
Go to CPAN Search website and search for the module that you wish to download. In this example, let us search, download and install XML::Parser Perl module. I have downloaded the XML-Parser-2.36.tar.gz to /home/download

# cd /home/download
# gzip -d XML-Parser-2.36.tar.gz
# tar xvf XML-Parser-2.36.tar
# cd XML-Parser-2.36

Build the perl module:
Build by running Makefile.PL, remember the case sensitivity, make and make test.

# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for XML::Parser::Expat
Writing Makefile for XML::Parser
# make
# make test

Install the perl module:
Now your package is ready to install.

# make install

As a newbie it looks pretty simple, and one go. But, luckily this is a very simple one module with no dependencies. Typically, Perl modules will be dependent on several other modules. Just imagine chasing all these dependencies one-by-one, thinking ... oh ye I got it. That will be very painful and annoying task. I recommend the CPAN method of installation as shown below.

Install Perl Modules using CPAN automatically

Logically, you should must have the CPAN perl module installed in your server or computer before you can install any other Perl modules using CPAN. I know you  are laughing, "to install a perl module you need another perl module"  ;)

Lets verify whether CPAN is already installed:

To install Perl modules using CPAN, make sure the cpan command is working. Following are the error message when CPAN module is not installed.

# cpan
-bash: cpan: command not found

# perl -MCPAN -e shell
Can't locate CPAN.pm in @INC (@INC contains:
/usr/lib/perl5/5.10.0/i386-linux-thread-multi
/usr/lib/perl5/5.10.0
/usr/local/lib/perl5/site_perl/5.10.0/i386-linux-thread-multi
/usr/local/lib/perl5/site_perl/5.10.0
/usr/lib/perl5/vendor_perl/5.10.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.10.0
/usr/lib/perl5/vendor_perl /usr/lib/perl5/site_perl/5.10.0 .).
BEGIN failed--compilation aborted.

Install the CPAN module using yum:
If CPAN in not installed in your system, you can use "yum" for the rescue. Dont worry biological data cruncher, this is true we are now dependent all these tiny magicians :).

# yum install perl-CPAN

Output of yum install perl-CPAN command:

Loaded plugins: refresh-packagekit
updates-newkey                       | 2.3 kB     00:00
primary.sqlite.bz2                   | 2.4 MB     00:00
Setting up Install Process
Parsing package install arguments

Resolving Dependencies
Transaction Summary
=============================================================================
Install      5 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): perl-ExtUtils-ParseXS-2.18-31.fc9.i386.rpm     |  30 kB     00:00
(2/5): perl-Test-Harness-2.64-31.fc9.i386.rpm         |  70 kB     00:00
(3/5): perl-CPAN-1.9205-31.fc9.i386.rpm               | 217 kB     00:00
(4/5): perl-ExtUtils-MakeMaker-6.36-31.fc9.i386.rpm   | 284 kB     00:00
(5/5): perl-devel-5.10.0-31.fc9.i386.rpm              | 408 kB     00:00

Installing     : perl-ExtUtils-ParseXS                             [1/5]
Installing     : perl-devel                                        [2/5]
Installing     : perl-Test-Harness                                 [3/5]
Installing     : perl-ExtUtils-MakeMaker                           [4/5]
Installing     : perl-CPAN                                         [5/5]


Installed: perl-CPAN.i386 0:1.9205-31.fc9
Dependency Installed:
  perl-ExtUtils-MakeMaker.i386 0:6.36-31.fc9
  perl-ExtUtils-ParseXS.i386 1:2.18-31.fc9
  perl-Test-Harness.i386 0:2.64-31.fc9
  perl-devel.i386 4:5.10.0-31.fc9
Complete!

Configure cpan the first time:
Once the CPAN is installed, you need to configure it by executing cpan, you should set some configuration parameters as shown below. I have shown only the important configuration parameters below. Accept all the default values by pressing enter.

Note: Make sure to execute “o conf commit” in the cpan prompt after the configuration to save the settings.

# cpan

Sorry, we have to rerun the configuration dialog for CPAN.pm due
to some missing parameters...

CPAN build and cache directory? [/root/.cpan]
Download target directory? [/root/.cpan/sources]
Directory where the build process takes place? [/root/.cpan/build]

Always commit changes to config variables to disk? [no]
Cache size for build directory (in MB)? [100]
Let the index expire after how many days? [1]

Perform cache scanning (atstart or never)? [atstart]
Cache metadata (yes/no)? [yes]
Policy on building prerequisites (follow, ask or ignore)? [ask]

Parameters for the 'perl Makefile.PL' command? []
Parameters for the 'perl Build.PL' command? []

Your ftp_proxy? []
Your http_proxy? []
Your no_proxy? []
Is it OK to try to connect to the Internet? [yes]

First, pick a nearby continent and country by typing in the number(s)
(1) Africa
(2) Asia
(3) Central America
(4) Europe
(5) North America
(6) Oceania
(7) South America
Select your continent (or several nearby continents) [] 5

(1) Bahamas
(2) Canada
(3) Mexico
(4) United States
Select your country (or several nearby countries) [] 4

(2) ftp://carroll.cac.psu.edu/pub/CPAN/
(3) ftp://cpan-du.viaverio.com/pub/CPAN/
(4) ftp://cpan-sj.viaverio.com/pub/CPAN/
(5) ftp://cpan.calvin.edu/pub/CPAN
(6) ftp://cpan.cs.utah.edu/pub/CPAN/
e.g. '1 4 5' or '7 1-4 8' [] 2-16

cpan[1]> o conf commit
commit: wrote '/usr/lib/perl5/5.10.0/CPAN/Config.pm'

cpan[2]> quit
No history written (no histfile specified).
Lockfile removed.

  • Install Perl Modules using CPAN

Hey smile please, now you are ready with CPAN and can download modules in one line command.

You can use one of the following method to install a Perl module using cpan:

# perl -MCPAN -e 'install Bundle::BioPerl'

(or)

# cpan
cpan shell -- CPAN exploration and modules installation (v1.9205)
ReadLine support available (maybe install Bundle::CPAN or Bundle::CPANxxl?)

cpan[1]> install "Bundle::BioPerl"

In the example above, CPAN will check for Bundle::BioPerl dependencies and automatically resolves and installs Bundle::BioPerl with all the dependent Perl modules.

  • Quick Ways

Oh, look at your face.. smily hmm :). This is what your are looking for, a quick and best way to install Perl modules, Bioperl. Following are the the steps to download BioPerl in your server/computer.

# sudo apt-cache search perl BioPerl

Output will be like as follows:

bioperl - Perl tools for computational molecular biology
bioperl-run - BioPerl wrappers: scripts
libbio-perl-perl - BioPerl core perl modules
libbio-perl-run-perl - BioPerl wrappers: modules
libbio-samtools-perl - Perl interface to SamTools library for DNA sequencing
libbiojava-java - Java API to biological data and applications (default version)
libbiojava3-java - Java API to biological data and applications (default version)
python-biopython-sql - Biopython support for the BioSQL database schema
libbtlib-perl - library for basic sequence manipulation

# sudo apt-get install bioperl

If it is installed then flash the following message:

Reading package lists... Done
Building dependency tree      
Reading state information... Done
bioperl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.

In it is found not installed in your server or system them install all with dependencies.

You can use the same approach to install all the modules, and packages if required.

Thanks for reading. Best of luck for your research.

Comments

  • Jit 2449 days ago

    Install cpanm to make installing other modules easier (you'll thank us later). You need to type these commands into a Terminal emulator (Mac OS XWin32Linux)

    cpan App::cpanminus
    

    Now install any module you can find.

    cpanm Module::Name
  • BioStar 1612 days ago

    #To install perl modules

    perl -MCPAN -e shell # go to CPAN install mode
    install Bundle::CPAN # update CPAN
    reload cpan
    install Set::Scalar

  • Neel 1465 days ago

    Check the perl module 

    Test if dependencies are met by running this perl one-liner:

    perl -e "use JSON::XS;"
  • Rahul Nayak 1413 days ago
    # envname is the name of your (existing) conda env
    conda activate envname
    # cpanm is available on either conda-forge or
    # bioconda, so add conda-forge (or look up
    # how to set up bioconda if you need tools
    # for bioinformatics)
    conda config --add channels conda-forge
    # Install cpanm
    conda install perl-app-cpanminus
    # packagename is the name of the Perl package you want
    cpanm packagename
  • Abhi 1168 days ago

    If you are on Conda, you can try installing cpamn 

    https://anaconda.org/bioconda/perl-app-cpanminus

    and then

    cpanm install <name>

     

  • Neel 876 days ago

    If you are on Ubuntu

    https://packages.ubuntu.com/bionic/bioperl

    sudo apt-get install <name_mentioned_in_list>

  • BioStar 653 days ago

    To install BioPerl on a macOS system, you can follow these steps:

      1. Open the Terminal app on your macOS system.

      2. Install Homebrew if you haven't already installed it by entering the following command:

      3. Update Homebrew by entering the following command:

        brew update
      4. Install Perl by entering the following command:

        brew install perl
      5. Install cpanminus by entering the following command:

        brew install cpanminus
      6. Install BioPerl by entering the following command:

        cpanm BioPerl
      7. Verify the installation by running a BioPerl script or entering the following command to check the BioPerl version:

        perl -MBio::Perl -e 'print "$Bio::Perl::VERSION\n"'

      If there are any issues with the installation, you can try searching for solutions online or consulting the BioPerl documentation.

  • BioStar 647 days ago

    Installing in CONDA env

    You can check using which perl - it should give you the perl that's located within your conda environment. In this case, it should install things into your conda-directory.

    When you install packages via cpan it will also print the folder perl is installing the package into.

    If you want to be extra-sure, you can also install most Perl packages via conda. Replace the ':' by '-', lower-case everything, and add 'perl-' to the beginning. In your case,

    conda install -c bioconda perl-lwp-simple
    

    this will definitely install into conda.

  • BioStar 647 days ago

    If using conda

    conda create --name perlENV perl

    conda activate perlENV

    conda install -c bioconda perl-bundle-bioperl

    conda install -c bioconda perl-bioperl