Some of the scripts I’ve written and posted on this site require various CPAN modules to be present on the system where the scripts are used. For the benefit of those who haven’t installed one of these modules before, here’s a step by step using Net::IPv6Addr as an example.
- First, switch to the root user; i.e. “su – root” or “sudo su – root” or ssh in as root if your server allows it.
- Now, as root, run one simple command: make
- If the above spits out something like this:
# make make: *** No targets specified and no makefile found. Stop.
then all is good and you can proceed to step 4. If instead, you see this:
firstname.lastname@example.org:~# make -bash: make: command not found
Then you do not have make installed. Run this to install it (assuming CentOS/RHEL): yum install make -y
- Next command to run, as root, is: perl -MCPAN -e shell
- If you see the following error, your operating system distribution is missing the CPAN shell module:
Can’t locate CPAN.pm in @INC (@INC contains: /root/bin /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed–compilation aborted.
- If that’s the case and you’re on CentOS, just run this: yum install perl-CPAN -y
- Try the shell command again: perl -MCPAN -e shell
- If this is the first time running that command, you will see one of the following prompts:
Are you ready for manual configuration? [yes]
If you see that one, type no and press enter.
Would you like me to configure as much as possible automatically? [yes]
If you see that one, just press enter.
- After setting up for the first time, when you run “perl -MCPAN -e shell” you’ll typically just see the following interactive shell:
Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v1.7602) ReadLine support available (try 'install Bundle::CPAN') cpan>
- From the “cpan> ” prompt, run: install Net::IPv6Addr
- This is a good example of some things you might encounter when installing modules because it has dependencies on other modules that the CPAN shell will try to help you install. You should see some output similar to the following when you run the install command; I’ve stripped out some of the file copying and compiling pieces so expect to see even more than what I’ve pasted in here:
CPAN: Storable loaded ok Going to read /root/.cpan/Metadata Database was generated on Fri, 12 Jul 2013 11:07:36 GMT CPAN: LWP::UserAgent loaded ok Fetching with LWP: ftp://cpan.cs.utah.edu/CPAN/authors/01mailrc.txt.gz Going to read /root/.cpan/sources/authors/01mailrc.txt.gz CPAN: Compress::Zlib loaded ok Fetching with LWP: ftp://cpan.cs.utah.edu/CPAN/modules/02packages.details.txt.gz Going to read /root/.cpan/sources/modules/02packages.details.txt.gz Database was generated on Mon, 15 Jul 2013 11:17:02 GMT Fetching with LWP: ftp://cpan.cs.utah.edu/CPAN/modules/03modlist.data.gz Going to read /root/.cpan/sources/modules/03modlist.data.gz Going to write /root/.cpan/Metadata Running install for module Net::IPv6Addr Running make for T/TM/TMONROE/Net-IPv6Addr-0.2.tar.gz Fetching with LWP: ftp://cpan.cs.utah.edu/CPAN/authors/id/T/TM/TMONROE/Net-IPv6Addr-0.2.tar.gz CPAN: Digest::MD5 loaded ok Fetching with LWP: ftp://cpan.cs.utah.edu/CPAN/authors/id/T/TM/TMONROE/CHECKSUMS CPAN.pm: Going to build T/TM/TMONROE/Net-IPv6Addr-0.2.tar.gz Checking if your kit is complete... Looks good Warning: prerequisite Math::Base85 0 not found. Warning: prerequisite Net::IPv4Addr 0 not found. Writing Makefile for Net::IPv6Addr ---- Unsatisfied dependencies detected during [T/TM/TMONROE/Net-IPv6Addr-0.2.tar.gz] ----- Math::Base85 Net::IPv4Addr Shall I follow them and prepend them to the queue of modules we are processing right now? [yes]
- So we’ve hit our first snag. The Net::IPv6Addr module has two dependencies that this server does not have present; Math::Base85 and Net::IPv4Addr. Fortunately, you don’t even have to drop back to the prompt and install those first, the shell asks if you’d like to install them first and the default is yes, so just press enter. Sometimes you may find that you have to go through numerous stages of this to get a module you want installed if it has dependencies and those dependencies have dependencies, etc. Fortunately these two install by themselves so the rest goes smoothly:
Delayed until after prerequisites Running make install Delayed until after prerequisites Running install for module Math::Base85 Running make for T/TM/TMONROE/Math-Base85-0.2.tar.gz Fetching with LWP: ftp://cpan.cs.utah.edu/CPAN/authors/id/T/TM/TMONROE/Math-Base85-0.2.tar.gz Checksum for /root/.cpan/sources/authors/id/T/TM/TMONROE/Math-Base85-0.2.tar.gz ok CPAN.pm: Going to build T/TM/TMONROE/Math-Base85-0.2.tar.gz Checking if your kit is complete... Looks good Writing Makefile for Math::Base85 cp Base85.pm blib/lib/Math/Base85.pm Manifying blib/man3/Math::Base85.3pm /usr/bin/make -- OK Running make install Installing /usr/lib/perl5/site_perl/5.8.8/Math/Base85.pm Installing /usr/share/man/man3/Math::Base85.3pm Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Math/Base85/.packlist Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod /usr/bin/make install -- OK Running install for module Net::IPv4Addr Running make for F/FR/FRAJULAC/Net-IPv4Addr-0.10.tar.gz Fetching with LWP: ftp://cpan.cs.utah.edu/CPAN/authors/id/F/FR/FRAJULAC/Net-IPv4Addr-0.10.tar.gz Fetching with LWP: ftp://cpan.cs.utah.edu/CPAN/authors/id/F/FR/FRAJULAC/CHECKSUMS Checksum for /root/.cpan/sources/authors/id/F/FR/FRAJULAC/Net-IPv4Addr-0.10.tar.gz ok CPAN.pm: Going to build F/FR/FRAJULAC/Net-IPv4Addr-0.10.tar.gz Checking if your kit is complete... Looks good Writing Makefile for Net::IPv4Addr Running make install Manifying blib/man1/ipv4calc.1 Manifying blib/man3/Net::IPv4Addr.3pm Installing /usr/lib/perl5/site_perl/5.8.8/auto/Net/IPv4Addr/autosplit.ix Installing /usr/lib/perl5/site_perl/5.8.8/Net/IPv4Addr.pm Installing /usr/share/man/man1/ipv4calc.1 Installing /usr/share/man/man3/Net::IPv4Addr.3pm Installing /usr/bin/ipv4calc Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Net/IPv4Addr/.packlist Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod /usr/bin/make install -- OK Running make for T/TM/TMONROE/Net-IPv6Addr-0.2.tar.gz Is already unwrapped into directory /root/.cpan/build/Net-IPv6Addr-0.2 CPAN.pm: Going to build T/TM/TMONROE/Net-IPv6Addr-0.2.tar.gz Running make install Installing /usr/lib/perl5/site_perl/5.8.8/Net/IPv6Addr.pm Installing /usr/share/man/man3/Net::IPv6Addr.3pm Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Net/IPv6Addr/.packlist Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod /usr/bin/make install -- OK
- And there we have it, Net::IPv6Addr is now installed along with its prerequisites so any perl script you want to run that has a “use Net::IPv6Addr” at the top will now have what it needs.