Installing perl
modules can be troublesome, especially when you’re not a ROOT user. After a lot of “pain”, I decide to document the two ways to install perl
modules (it’s not my creation, just for a memo).
Check installed
First, check if the module has been installed:
1 | system perl |
Scenario 1: you’re a ROOT user OR use your own perl
In this case, the installation is simple.
Use cpan -i module_name
1 | ~/software/perl.5.24.0/bin/cpan -i Net::Server |
Use perl -MCPAN -e shell
1 | ~/software/perl.5.24.0/bin/perl -MCPAN -e shell |
Scenario 2: you’re a common user but want to use the system perl
Install packages from source
This process can be tedious, especially if the modules you want to install depend on other modules.
Sometimes, even we have installed own perl
, but still need to use the perl
under /usr/bin/perl
.
First, create a directory for perl
modules. This directory would be used to store perl modules.
1 | mkdir -p /home/niuyw/bin/perl_lib |
Second, download a module and install it from source code locally. Go CPAN to search and download the modules you want to install.
1 | tar zxf Capture-Tiny-0.46.tar.gz && cd Capture-Tiny-0.46 |
Third, add the path above to your .bashrc
. Notice the format.
1 | export PERL5LIB=$PERL5LIB:/home/niuyw/bin/perl_lib/share/perl5:/home/niuyw/bin/perl_lib/lib64/perl5 |
Use cpanm
cpanm is a perl module to help users to get, unpack build and install modules from CPAN.
First, install cpanm
1 | download |
Help information.
1 | ~/bin/perl_lib/bin/cpanm -h |
Install packages.
1 | ~/bin/perl_lib/bin/cpanm -l /home/niuyw/bin/perl_lib Log::Log4perl Math::CDF |
Footnote
Thanks Quan Kang for teaching me how to install perl modules from source code.
Change log
- 20180413: create the note
- 20180414: change the setting of
PERL5LIB
- 20190402: add the section “use cpanm”