Install your own Perl modules

Source: Internet
Author: User
Tags install perl virtual private server

Install your own Perl modules. If you do not have the root permission, install Perl modules in your home directory.

From: http://servers.digitaldaze.com/extensions/perl/modules.html

Installing perl5 modules locally

Normally, the perl5 module installation procedure includes des commands something like these:

% Perl5 makefile. pl
% Make
% Make test
% Make install
% Make clean

The first command,Perl5 makefile. pl, Directs perl5 to createMakefileFor the new module you are installing. When installing a perl5 ModuleLocallyYou must designate the Home Directory of your perl5 installation on the command line. That information is used by perl5 to create the makefile. substitute the following commandPerl5 makefile. pl:

% Perl5 makefile. pl prefix =/usr/home/Username/Usr/local

The ValueUsernameAbove shoshould be replaced with your virtual private server primary user account name. So the complete installation process is:

% Perl5 makefile. pl prefix =/usr/home/Username/Usr/local
% Make
% Make test
% Make install
% Make clean

For older modules it may be necessary to designate several other variables on the command line during the module installation:

% Perl5 makefile. pl prefix =/usr/home/Username/Usr/local \ installprivlib =/usr/home/Username/Usr/local/lib/perl5 \ installscript =/usr/home/Username/Usr/local/bin \ installsitelib =/usr/home/Username/Usr/local/lib/perl5/site_perl \ installbin =/usr/home/Username/Usr/local/bin \ installman1dir =/usr/home/Username/Usr/local/lib/perl5/man \ installman3dir =/usr/home/Username/Usr/local/lib/perl5/man/man3

To save yourself some typing you can create a file and put these variable assignments abve in to a file (Filename) Something like this:

Prefix =/usr/home/Username/Usr/local \ installprivlib =/usr/home/Username/Usr/local/lib/perl5 \ installscript =/usr/home/Username/Usr/local/bin \ installsitelib =/usr/home/Username/Usr/local/lib/perl5/site_perl \ installbin =/usr/home/Username/Usr/local/bin \ installman1dir =/usr/home/Username/Usr/local/lib/perl5/man \ installman3dir =/usr/home/Username/Usr/local/lib/perl5/man/man3

Then, each time you install a perl5 module you can use the following syntax:

% Perl5 makefile. pl 'catFilename
% Make
% Make test
% Make install
% Make clean

You also can have a few different local module installation procedures, for example one for production Perl and another for development:

% Perl5 makefile. pl 'catFilename. Production'

Or

% Perl5 makefile. pl 'catFilename. Development'
Making scripts find the modules you have installed

When you install perl5 on your virtual private server, all pre-installed modules are installed into these 4 directories (depending on which version of perl5 you are installing ):

/Usr/local/lib/perl5/usr/local/lib/perl5/i386-bsdos/5.00x/usr/local/lib/perl5/site_perl/i386-bsdos/usr/local/lib/perl5 /site_perl

These 4 directories are already preset in the perl5's@ INCArray. this array contains the paths that perl5 searches in order to find modules. if you install perl5 modules locally as described above, you will need to append these two directories, which are local to your virtual private server, to@ INCArray:

/Usr/home/<username>/usr/local/lib/perl5/usr/home/<username>/usr/local/lib/perl5/site_perl

The architecture specific directories are being searched by Perl automatically each time you want to use modules in that path you shoshould Add the following line to your scripts:

Use lib QW (/usr/home/Username/Usr/local/lib/perl5/usr/home/Username/Usr/local/lib/perl5/site_perl );

You don't have to put it into a begin block;Lib. PMModule takes care of that for you. It also adds the architecture specific directories.

You also can use a begin block to include your installed modules:

Begin {unshift @ INC, QW (/usr/home/Username/Usr/local/lib/perl5/usr/home/Username/Usr/local/lib/perl5/site_perl );}

However,Use libConstruct seems to be cleaner andUnshift @ INCConstruct doesn' t automatically add the architecture specific directories to@ INCArray.

Installing new modules that require locally installed modules

Okay, imagine that you have installed module A in/Usr/home/username/usr/local/lib/perl5. Now you want to install a module B that demands module A to be already installed. You know that you have installed the module, but amazingly B can't locate it. Why? Because when you try to install the Module B It doesn't know that you have module A installed locally. perl5 searches the basic 4 directories as defined by default in@ INCArray. But your local directories aren't listed there.

The solution is simple.Perl5libEnvironment variable does the same job in the shellUse libDoes in your script. So if you useCSHOrTcsh, Type the following at the command line:

% Setenv perl5lib \/usr/home/<username>/usr/local/lib/perl5:/usr/home/<username>/usr/local/lib/perl5/site_perl

Check the man page of your favorite shell how to set the environment variables if you use a shell different from CSH/tcsh. Put thisSetenvStatement. LoginOr another file that is being sourced each time you log in into your account and you will not have to remember setting it each time you login.

Module installation using CPAN. PM

An alternative to manually installing perl5 modules isCPAN. PMModule (see www.perl.com/cpan/) which automates module download and installation. If you have perl5.004 or higher installed you have it bundled with the distribution. If not, you can download it from CPAN.

When you initially runPerl5-mcpan-e ShellCommand, it will ask you a few questions. You can use all the defaults, before t for this one:

Parameters for the 'perl makefile. pl' command? [] Prefix =/usr/home/<username>/usr/local

And this one:

Parameters for the 'Make install' command? [] Installman3dir =/usr/home/<username>/usr/local/lib/perl5/man/man3

After configuration of the module is complete, you will see>Prompt. Then you can try installing modules. to install the CGI Module, do this:

> Install CGI

It will fetch the latest CGI Module, unpack it, make it, test it and install it into your local area or the directory you specified asPrefixDirectory. The command:

> I/cgi/

Will return the list of modules that match that pattern.

TheCPAN. PMModule has more functionality, like checking for the latest modules, for example. Just runPerldoc CPANTo read the man page.

 

Complete!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.