When running Perl script under fresh Linux system, many of Linux users experience error message called “Can’t locate … in @INC (@INC contains:” . It means Pearl executor is unable to find required Perl module. It may be due to broken Perl module, but most of the time fresh Linux OS only installed few essentials modules by default. Here I’m going to describe how to fix that error by installing Perl modules which is needed for Perl script. You can install Perl module manually but it is bit hard and time consuming thing 🙂 , instead automatically process is recommended. Following steps are for Centos, RHEL based system, however logic is similar for any UNIX distribution.
1) Installing CPAN
1 |
#yum install perl-CPAN |
2) Installing Perl modules
1 |
#perl -MCPAN -e shell |
You can keep default settings like below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
CPAN.pm requires configuration, but most of it can be done automatically. If you answer 'no' below, you will enter an interactive dialog for each configuration option instead. Would you like to configure as much as possible automatically? [yes] <install_help> Warning: You do not have write permission for Perl library directories. To install modules, you need to configure a local Perl library directory or escalate your privileges. CPAN can help you by bootstrapping the local::lib module or by configuring itself to use 'sudo' (if available). You may also resolve this problem manually if you need to customize your setup. What approach do you want? (Choose 'local::lib', 'sudo' or 'manual') [local::lib] Autoconfigured everything but 'urllist'. Now you need to choose your CPAN mirror sites. You can let me pick mirrors for you, you can select them from a list or you can enter them by hand. Would you like me to automatically choose some CPAN mirror sites for you? (This means connecting to the Internet) [yes] Trying to fetch a mirror list from the Internet Fetching with HTTP::Tiny: http://www.perl.org/CPAN/MIRRORED.BY Looking for CPAN mirrors near you (please be patient) ........................ done! ..... //skip some lines ..... Would you like me to append that to /root/.bashrc now? [yes] commit: wrote '/root/.cpan/CPAN/MyConfig.pm' |
3) Example Perl module installation
Example error :-
Can’t locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl/usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5
Error message clearly indicate system is missing this “ExtUtils/MakeMaker.pm” module. So let’s look at how to fix it.
inside CPAN shell type following command.That’s it see you soon !!
1 |
> install ExtUtils::MakeMaker |