Install and use the local Perl module in Linux

Source: Internet
Author: User
Tags perl script

When using Linux or UNIX, Perl is a very useful scripting language. There are many introductions on Perl module installation on the Internet. On the one hand, you can install it using software installation tools provided by different kits, on the other hand, you can install it through CPAN, and on the other hand, you can directly compile the source code.

 

In this way, for users with root permissions, there is no problem, but for general users who do not have root permissions, if you want to install and use the Perl module in your home directory, there are many other special features. Here I will introduce how to install and use the Perl module in the home directory of a common user.

Compilation and installation module:

Generally, there are several basic steps:

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

 

Unlike installation with root permissions, users mustStep 1Specify the target path of the installation module with proper permissions.

For example, Perl makefile. pl -- prefix =/home/username/usr

Let your script find the module you have installed

 

After you install the module under/home/username/usrProgramYesUse these modulesYou can achieve this in two ways:

Use lib QW (/home/username/usr/lib/perl5/home/username/usr/lib/perl5/site_perl );

Or begin {unshift @ INC, QW (/usr/home/username/usr/local/lib/perl5/usr/home/username/usr/local/lib/perl5/site_perl );}

The principle is that the path of the Perl search module is stored in the @ INC array. You only need to add the custom module path to the array.

 

Set the search path for the Perl module outside the Perl script

If you need to set a search path for the Perl module outside the Perl script (for example, to solve the dependency between the installation module), you can useSet Environment Variables. The method is as follows:

Export perl5lib = \
/Home/<username>/usr/lib/

/Home/<username>/usr/lib/perl5/site_perl

Of course, if you put it in. bashrc, this setting can be laterIt works every time you log on to the system..

 

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.