Using cpanminus

If you haven’t already tried cpanminus (cpanm) then you definitely should do.

cpanm is a replacement/supplement for cpan that provides much less functionality and therefore faster and simpler.

We are accustomed to more – more features, faster speed, etc. – but sometimes we don’t need more features. Sometimes we just want a tool to do the job and do it quickly and efficiently. Over the years the cpan command has grown in response to requirements and, as any dev that has worked with software that has evolved this way knows, this leads to things getting slower and clunkier because you generally can’t strip out how the application used to work, only add new features.

cpanminus is a replacement for cpan which is designed to get modules installed quickly and that is all. This is often all I need and so I find it so useful rather than starting up cpan and having it download the updated module lists from CPAN before I can do anything.

Best of all cpanm is self-installing. So while cpanm is a Perl module (App::cpanminus) you don’t have to use cpan to install the module in order to use it. Instead you can download the perl script and tell it to install itself using:

curl -L http://cpanmin.us | perl - --self-upgrade

This means that it works well with Perlbrew installations of Perl.

Self-installing (bootstrapping, whatever you want to call it) seems to be a trend with some newer Perl applications which only makes them easier to use.

Once installed you simply type:

cpanm -i <module>

and through the powers of the cpanmeta database it will find and install your module. In my experience it is generally faster to use than the regular cpan.

I have two issues with the application which are both factors of the module installation process.

1. cpanm downloads files to a working folder that has a unique name based on a time stamp. If a module that you are installing fails to install then the next time that you try to install the module it is downloaded again to a new folder with a different time stamp. This can lead you to duplicating the downloads numerous times if you have installation issues (missing libraries is usually the reason).

2. If an installation fails then it directs you to read the build.log file:

! Installing XML::Parser failed. See /home/colin/.cpanm/build.log for details.

but that file is a symlink to the build.log file in the latest build folder, so if you build again then a new folder and new build log are created. That is okay except if you want to find the older version. In that case you have to work out what folder is what.

On the whole though these are minor points and cpanm is definitely my go-to installer now.

(Updated 25th Sept to correct spelling mistake and assign to a category)

Advertisements

2 Responses to Using cpanminus

  1. alias says:

    Hi. just tried this but every time i try:
    cpanm -i XML::Parser
    It says:
    Finding XML::Parser on cpanmetadb failed.
    –> Working on XML::Parser
    Fetching http://www.cpan.org/authors/id/T/TO/TODDR/XML-Parser-2.41.tar.gz … FAIL
    ! Download http://www.cpan.org/authors/id/T/TO/TODDR/XML-Parser-2.41.tar.gz failed. Retrying …
    ! Download http://www.cpan.org/authors/id/T/TO/TODDR/XML-Parser-2.41.tar.gz failed. Retrying …
    ! Download http://www.cpan.org/authors/id/T/TO/TODDR/XML-Parser-2.41.tar.gz failed. Retrying …
    ! Failed to download http://www.cpan.org/authors/id/T/TO/TODDR/XML-Parser-2.41.tar.gz

    I just cant’t get it to fetch anything. Any thoughts? is there a pre-requisite like a fetch module i need in perl or something? can itell it to use curl or wget maybe?

    • perladmin says:

      The error is saying that it can’t connect to cpan to download the file. It hasn’t even fetched the archive yet, let alone tried to build it.

      If you are still getting it see if the issue is networking

      ping 199.15.176.140

      Should get a response. If not check if you can reach anywhere from the box. Do you have a default route?

      netstat -rn | grep '^0'

      E.g.

      0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth1

      Is that the correct IP address for your router (here it is 192.168.2.1) and is that the correct interface (here eth1)?

      If so check the DNS resolution with the command:

      host www.cpan.org

      If you get a response which includes the IP above the it works as expected. So try pinging the above address:

      ping www.cpan.org

      If you get a response you should be able to download files. In that case try:

      wget http://www.cpan.org/authors/id/T/TO/TODDR/XML-Parser-2.41.tar.gz

      It should download. If not are you using a web proxy or firewall which is blocking the connection? (maybe on the router?)

      If you do download it via wget then you can use cpanm XML-Parser-2.41.tar.gz to install it using that bundle.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: