Friday, 22 March 2013

The world's easiest guide to installing cpanm

A lot of the software I write is in Perl, and the easiest way to install it is almost always using cpanm. Here I present to you the world's easiest guide to getting cpanm up and running.

If you're in a hurry, just run these and you're done.
curl -L | perl - --self-upgrade
~/perl5/bin/cpanm local::lib
perl -I ~/perl5/lib/perl5 -Mlocal::lib >> ~/.bashrc
Now start a new shell, and you're done.

Full instructions...

Firstly, you need perl installed on your machine. I'm not covering that here, there are lots of good guides. If you're on Ubuntu, Debian, or anything based off Debian, it's just sudo apt-get install perl.

Installing cpanm

First, grab cpanm from the web:
curl -L | perl - --self-upgrade
If you don't have curl, then:
wget -O - | perl - --self-upgrade
And if you don't have either, just go to, right click, and save the source as cpanm. Then run perl cpanm --self-upgrade.

Installing local::lib

cpanm will install itself in ~/perl5/bin/cpanm by default. It'll also install new modules and supporting files into ~/perl5 . However you probably don't have these in your path. While you can set things up manually, it's much easier to install local::lib.  We can do that with:
~/perl5/bin/cpanm local::lib
Now we can use local::lib to set up our environment variables.  If you want, you can run perl -I ~/perl5/lib/perl5/ -Mlocal::lib to print them. Here's what mine look like:
export PERL_LOCAL_LIB_ROOT="/home/pjf/perl5";
export PERL_MB_OPT="--install_base /home/pjf/perl5";
export PERL_MM_OPT="INSTALL_BASE=/home/pjf/perl5";
export PERL5LIB="/home/pjf/perl5/lib/perl5/i686-linux-gnu-thread-multi-64int:/home/pjf/perl5/lib/perl5:$PERL5LIB";
export PATH="/home/pjf/perl5/bin:$PATH";
You could run these, but it's way easier to just add the appropriate command to your .bashrc file and never worry about it again. Assuming you're using bash as your shell:
perl -I ~/perl5/lib/perl5 -Mlocal::lib >> ~/.bashrc
Now start a new shell, and you'll have access to cpanm, all Perl programs will be able to find the modules you install (there's no need for root access), and you'll be able to install new things from the cpan with cpanm Module::Name.


Flattr this

No comments:

Post a Comment