Как устанавливать модули Perl вручную и используя CPAN
How To Install Perl Modules Manually and Using CPAN commandby on September 18, 2008
Installing Perl modules required by various open source software is a routine tasks for sysadmins. Installing Perl modules manually by resolving all the dependencies is tedious and annoying process.
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 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 .)
Install Perl Modules Manually
Download Perl moduleGo 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
# 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
# make install
This is very simple for one module with no dependencies. Typically, Perl modules will be dependent on several other modules. Chasing all these dependencies one-by-one can be very painful and annoying task. I recommend the CPAN method of installation as shown below. Use the manual method only if the server is not connected to the Internet.
Install Perl Modules using CPAN automatically
Verify whether CPAN is already installed
To install Perl modules using CPAN, make sure the cpan command is working. You should have the CPAN perl module installed before you can install any other Perl modules using CPAN. In this example, 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
# 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
The first time when you execute 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
You can use one of the following method to install a Perl module using cpan.
# /usr/bin/perl -MCPAN -e 'install Email::Reply' (or) # cpan cpan shell -- CPAN exploration and modules installation (v1.9205) ReadLine support available (maybe install Bundle::CPAN or Bundle::CPANxxl?) cpan[1]> install "Email::Reply";
Output of above perl install command:
CPAN: Storable loaded ok (v2.18) Going to read /root/.cpan/Metadata Database was generated on Mon, 15 Sep 2008 11:02:52 GMT Running install for module 'Email::Reply' Running make for R/RJ/RJBS/Email-Reply-1.202.tar.gz CPAN: LWP::UserAgent loaded ok (v2.036) CPAN: Time::HiRes loaded ok (v1.9711) Fetching with LWP: ftp://carroll.cac.psu.edu/pub/CPAN/authors/id/R/RJ/RJBS/Email-Reply-1.202.tar.gz CPAN: checksum security checks disabled because Digest::SHA not installed. Please consider installing the Digest::SHA module. CPAN: Compress::Zlib loaded ok (v2.008) Email-Reply-1.202/ Email-Reply-1.202/Changes CPAN: File::Temp loaded ok (v0.18) Warning: prerequisite Email::Abstract 2.01 not found. Warning: prerequisite Email::MIME::Creator 1.41 not found. Writing Makefile for Email::Reply ---- Unsatisfied dependencies detected during ---- ---- RJBS/Email-Reply-1.202.tar.gz ---- Email::Abstract [requires] Email::MIME::Creator [requires] Shall I follow them and prepend them to the queue of modules we are processing right now? [yes] [Note: CPAN automatically detects that Email::Abstract and Email::MIME::Creator is required] Fetching with LWP: ftp://server/pub/CPAN/authors/id/R/RJ/RJBS/Email-Abstract-2.134.tar.gz make -- OK make install -- OK Fetching with LWP: ftp://server/pub/CPAN/authors/id/R/RJ/RJBS/Email-MIME-Creator-1.454.tar.gz make -- OK make install -- OK Warning: prerequisite Email::Simple::Creator 1.4 not found. Writing Makefile for Email::MIME::Creator Email::Simple::Creator [requires] Shall I follow them and prepend them to the queue of modules we are processing right now? [yes] [Note: CPAN automatically detects that Simple::Creator is required] Fetching with LWP: ftp://carroll.cac.psu.edu/pub/CPAN/authors/id/R/RJ/RJBS/Simple-Creator.tar.gz make -- OK make install -- OK Fetching with LWP: CPAN.pm: Going to build R/RJ/RJBS/Email-Reply-1.202.tar.gz make -- OK make install -- OK
In the example above, Email::Reply is dependent on the several other modules. CPAN automatically resolves the dependencies and installs Email::Reply and all the dependent Perl modules.
If you liked this article, please bookmark it on del.icio.us and Stumble it.
http://www.thegeekstuff.com/2008/09/how-to-install-perl-modules-manually-and-using-cpan-command/
http://linux.die.net/man/1/perlmodinstall
Perl Modules Using CPAN
(With Snippets)
| Steve Litt is the author of Troubleshooting Techniques of the Successful Technologist, Rapid Learning: Secret Weapon of the Successful Technologist, and Samba Unleashed. |
Contents
Introduction
The Perl that comes stock on your Linux distribution or your Windows install is hugely powerful, but in fact it just scratches the surface. Throughout the years, people have created Perl modules to accomplish very specific tasks so that you don't need to rewrite the wheel to perform those same tasks.But these modules are not, by default, on your computer. They reside on the CPAN website at http://www.cpan.org. Often you can simply download the Perl code comprising the new module, and place that Perl code in the right place. But sometimes it requires a recompile.
When working with Linux, you can actually use Perl itself to download, make, test and install new modules. That's often preferable.
Running the Perl CPAN Shell
Downloading and installing new modules can be done entirely from within the Perl CPAN shell. Working within the CPAN shell always triggers a compile, which can be good or bad, depending on the situation.Obviously, if you have no C compiler (on a stock Windows box, for instance) or your C compiler is incompatible with the Perl modules, compiling is a bad thing. In cases where the new module is entirely Perl code, you'd be better downloading the module and manually placing it in the proper part of the Perl module tree. Also, compiling can take significant time, so you might want to go the straight Perl route. A further disadvantage of compiling is disk space. Source and object files take significant space, so if your /usr tree is almost full, you might want to stay away from compiles.
However, on fully compatible machines (Linux), using the CPAN shell with compiles is often the simplest route, and incorporates all features requiring recompilation.
To run the CPAN shell, AS ROOT run the following command:
perl -MCPAN -e 'shell'You will be shown a prompt like this:
cpan>From that prompt you can get help with the help command:
cpan> h Display Information command argument description a,b,d,m WORD or /REGEXP/ about authors, bundles, distributions, modules i WORD or /REGEXP/ about anything of above r NONE reinstall recommendations ls AUTHOR about files in the author's directory Download, Test, Make, Install... get download make make (implies get) test MODULES, make test (implies make) install DISTS, BUNDLES make install (implies test) clean make clean look open subshell in these dists' directories readme display these dists' README files Other h,? display this menu ! perl-code eval a perl command o conf [opt] set and query options q quit the cpan shell reload cpan load CPAN.pm again reload index load newer indices autobundle Snapshot force cmd unconditionally do cmd cpan> |
The main commands you'll use are get, make, test, and install. Although install would do all four, you should do them one at a time so that if there's an error you can better see exactly what happened. The clean command is helpful if you think you blew it and want to start over. look and readme are handy to see what's going on. You quit with q.
If it gripes about not having the proper header files, perhaps you don't have the header files for a higher level module. For instance, if your distro came with the .pm file for Tk, but not the headers, and then you try to compile Tk::JPEG, you would get such an error message. The solution is to get, make, test and install Tk, and then perform the same steps on Tk::JPEG.
http://www.troubleshooters.com/codecorn/littperl/perlcpan.htm
Perl – GTK2 – Ubuntu 9.04
http://www.allmyit.com.au/perl-gtk2-ubuntu-904
How to install CPAN modules
Here are some recommended approaches to installing modules from CPAN, as with much of Perl there are several alternatives.Some basics
Most Perl modules are written in Perl, some use XS (they are written in C) so require a C compiler (it's easy to get this setup - don't panic), see your OS of choice below to find out how to get the right compiler. Modules may have dependencies on other modules (almost always on CPAN) and cannot be installed without them (or without a specific version of them). It is worth throughly reading the documentation for the options below. Many modules on CPAN now require a recent version of Perl (version 5.8 or above).Quick start
Installcpanm to make installing other modules easier (you'll thank us later). You need to type these commands into a Terminal emulator (Mac OS X, Win32, X Windows/Linux)cpan App::cpanminusNow install any module you can find.
cpanm Module::Name http://www.cpan.org/modules/INSTALL.html