Difference between revisions of "Installing Perl Modules"
Line 209: | Line 209: | ||
cpan> | cpan> | ||
</pre> | </pre> | ||
+ | |||
+ | With installation finished, we can test it interactively: | ||
+ | |||
+ | <pre> | ||
+ | [user@submit2 ~]$ perl -e 'use File::Slurp;' | ||
+ | </pre> | ||
+ | |||
+ | If all went well, the above command will return with no errors. |
Revision as of 15:04, 6 June 2011
Though modern-day Linux and Unix systems may have many perl modules already installed, the time may come when you use a module that was not shipped with your system or installed by your administrator. Don't fret - you can do this all by yourself by using the CPAN module. This document will describe how to use the CPAN module to install perl modules into a subdirectory of your home area which we'll call perl5lib
.
CPAN Module Configuration
Execute the following command to start a CPAN shell:
$ perl -MCPAN -e shell
The first time you run this, an interactive question and answer session will be started as CPAN configures itself. You can take all the defaults until it asks whether you want any parameters for perl Makefile.PL:
Every Makefile.PL is run by perl in a separate process. Likewise we run 'make' and 'make install' in processes. If you have any parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass to the calls, please specify them here. If you don't understand this question, just press ENTER. Parameters for the 'perl Makefile.PL' command? Typical frequently used settings: POLLUTE=1 increasing backwards compatibility LIB=~/perl non-root users (please see manual for more hints) Your choice: []
You should answer with the following long line:
PREFIX=~/perl5lib/ LIB=~/perl5lib/lib INSTALLMAN1DIR=~/perl5lib/man1 INSTALLMAN3DIR=~/perl5lib/man3
You can take defaults again until it comes time to choose mirrors of www.cpan.org from which you can install from. Choose as many as you like; I chose:
ftp://mirrors.kernel.org/pub/CPAN/ ftp://mirrors1.kernel.org/pub/CPAN/ ftp://mirrors2.kernel.org/pub/CPAN/ ftp://mirror.sit.wisc.edu/pub/CPAN/ http://www.perl.com/CPAN/
After choosing your mirrors, press enter until you get the cpan>
prompt. Then quit (type 'q
').
Now tell perl to use your personal module repository by setting the PERL5LIB
environment variable. For Bourne shell users, you would do this:
$ PERL5LIB=~/perl5lib/lib $ export PERL5LIB
You should also add the above two lines to your ~/.bash_profile
so the PERL5LIB
variable will be automatically set when you next log in.
Then start up CPAN again:
$ perl -MCPAN -e shell
You will be immediately greeted with the cpan>
prompt. At the cpan>
prompt, enter the following to get CPAN to update itself:
install Bundle::CPAN reload cpan
and that's it!
Installing Additional Modules
Now that you have CPAN configured, you can install all the modules you want either from CPAN's interactive shell (perl -MCPAN -e shell
) or from the command line (perl -MCPAN -e 'install FOO::BAR'
). The modules will be installed into your ~/perl5lib/lib
directory.
As a full example, we'll install the File::Slurp
module into the username user
's ~/perl5lib
directory.
[user@submit2 ~]$ perl -MCPAN -e shell cpan shell -- CPAN exploration and modules installation (v1.7602) ReadLine support enabled cpan> install File::Slurp CPAN: Storable loaded ok Going to read /home/user/.cpan/Metadata Database was generated on Mon, 06 Jun 2011 09:27:35 GMT Running install for module File::Slurp Running make for U/UR/URI/File-Slurp-9999.18.tar.gz CPAN: LWP::UserAgent loaded ok Fetching with LWP: ftp://mirrors.kernel.org/pub/CPAN/authors/id/U/UR/URI/File-Slurp-9999.18.tar.gz CPAN: Digest::MD5 loaded ok Fetching with LWP: ftp://mirrors.kernel.org/pub/CPAN/authors/id/U/UR/URI/CHECKSUMS CPAN: Compress::Zlib loaded ok Checksum for /home/user/.cpan/sources/authors/id/U/UR/URI/File-Slurp-9999.18.tar.gz ok Scanning cache /home/user/.cpan/build for sizes Deleting from cache: /home/user/.cpan/build/Bundle-CPAN-1.858 (24.1>10.0 MB) Deleting from cache: /home/user/.cpan/build/ExtUtils-CBuilder-0.280202 (24.0>10.0 MB) Deleting from cache: /home/user/.cpan/build/Test-Harness-3.23 (23.9>10.0 MB) Deleting from cache: /home/user/.cpan/build/ExtUtils-MakeMaker-6.56 (21.9>10.0 MB) Deleting from cache: /home/user/.cpan/build/Module-Build-0.3800 (20.1>10.0 MB) Deleting from cache: /home/user/.cpan/build/PathTools-3.33 (19.1>10.0 MB) Deleting from cache: /home/user/.cpan/build/File-Temp-0.22 (18.2>10.0 MB) Deleting from cache: /home/user/.cpan/build/Scalar-List-Utils-1.23 (17.9>10.0 MB) Deleting from cache: /home/user/.cpan/build/Test-Simple-0.98 (17.4>10.0 MB) Deleting from cache: /home/user/.cpan/build/Data-Dumper-2.131 (16.6>10.0 MB) Deleting from cache: /home/user/.cpan/build/Compress-Raw-Bzip2-2.035 (15.9>10.0 MB) Deleting from cache: /home/user/.cpan/build/Compress-Raw-Zlib-2.035 (14.5>10.0 MB) Deleting from cache: /home/user/.cpan/build/libnet-1.22 (12.1>10.0 MB) Deleting from cache: /home/user/.cpan/build/TermReadKey-2.30 (11.5>10.0 MB) Deleting from cache: /home/user/.cpan/build/Term-ReadLine-Perl-1.0303 (11.0>10.0 MB) Deleting from cache: /home/user/.cpan/build/YAML-0.73 (10.6>10.0 MB) File-Slurp-9999.18/ File-Slurp-9999.18/t/ File-Slurp-9999.18/t/no_clobber.t File-Slurp-9999.18/t/edit_file.t File-Slurp-9999.18/t/write_file_win32.t File-Slurp-9999.18/t/error.t File-Slurp-9999.18/t/pod_coverage.t File-Slurp-9999.18/t/perms.t File-Slurp-9999.18/t/binmode.t File-Slurp-9999.18/t/pod.t File-Slurp-9999.18/t/file_object.t File-Slurp-9999.18/t/stdin.t File-Slurp-9999.18/t/prepend_file.t File-Slurp-9999.18/t/read_dir.t File-Slurp-9999.18/t/large.t File-Slurp-9999.18/t/paragraph.t File-Slurp-9999.18/t/error_mode.t File-Slurp-9999.18/t/TestDriver.pm File-Slurp-9999.18/t/handle.t File-Slurp-9999.18/t/data_list.t File-Slurp-9999.18/t/original.t File-Slurp-9999.18/t/append_null.t File-Slurp-9999.18/t/inode.t File-Slurp-9999.18/t/newline.t File-Slurp-9999.18/t/slurp.t File-Slurp-9999.18/t/tainted.t File-Slurp-9999.18/t/data_scalar.t File-Slurp-9999.18/t/pseudo.t File-Slurp-9999.18/t/stringify.t File-Slurp-9999.18/t/chomp.t File-Slurp-9999.18/TODO File-Slurp-9999.18/README File-Slurp-9999.18/lib/ File-Slurp-9999.18/lib/File/ File-Slurp-9999.18/lib/File/Slurp.pm File-Slurp-9999.18/MANIFEST File-Slurp-9999.18/META.yml File-Slurp-9999.18/Changes File-Slurp-9999.18/extras/ File-Slurp-9999.18/extras/slurp_bench.pl File-Slurp-9999.18/extras/slurp_article.pod File-Slurp-9999.18/extras/FileSlurp_12.pm File-Slurp-9999.18/Makefile.PL CPAN.pm: Going to build U/UR/URI/File-Slurp-9999.18.tar.gz Checking if your kit is complete... Looks good Writing Makefile for File::Slurp cp lib/File/Slurp.pm blib/lib/File/Slurp.pm Manifying blib/man3/File::Slurp.3pm /usr/bin/make -j2 -- OK Running make test PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/append_null.t ....... ok t/binmode.t ........... ok t/chomp.t ............. ok t/data_list.t ......... ok t/data_scalar.t ....... ok t/edit_file.t ......... ok t/error.t ............. ok t/error_mode.t ........ ok t/file_object.t ....... ok t/handle.t ............ ok t/inode.t ............. ok t/large.t ............. ok t/newline.t ........... ok t/no_clobber.t ........ ok t/original.t .......... ok t/paragraph.t ......... ok t/perms.t ............. ok t/pod.t ............... skipped: Test::Pod 1.14 required for testing POD t/pod_coverage.t ...... skipped: Test::Pod::Coverage 1.04 required for testing POD coverage t/prepend_file.t ...... ok t/pseudo.t ............ ok t/read_dir.t .......... ok t/slurp.t ............. ok t/stdin.t ............. ok t/stringify.t ......... ok t/tainted.t ........... ok t/write_file_win32.t .. ok All tests successful. Files=27, Tests=295, 3 wallclock secs ( 0.18 usr 0.08 sys + 1.93 cusr 0.54 csys = 2.73 CPU) Result: PASS /usr/bin/make test -- OK Running make install Manifying blib/man3/File::Slurp.3pm Appending installation info to /home/user/perl5lib/lib/x86_64-linux-thread-multi/perllocal.pod Installing /home/user/perl5lib/lib/File/Slurp.pm Installing /home/user/perl5lib/share/man/man3/File::Slurp.3pm /usr/bin/make install -j2 -- OK cpan>
With installation finished, we can test it interactively:
[user@submit2 ~]$ perl -e 'use File::Slurp;'
If all went well, the above command will return with no errors.