Can I install my own Perl CPAN modules?
For example, let’s say your script needs the Text::Lorem module, but you find it isn’t preinstalled when you try running this script:
#!/usr/bin/perl use Text::Lorem; print Text::Lorem->new()->words(5);
... and get the error “Can't locate Text/Lorem.pm in @INC (you may need to install the Text::Lorem module)”.
To fix this, you can install it for your account from the command-line shell using the cpan command. First run this in your shell session to tell cpan to save any installed modules locally:
eval `perl -Mlocal::lib`
The first time you run “cpan”, it will ask you “Would you like to configure as much as possible automatically?” — you should choose the default “yes”.
New modules will be installed by default in the /perl5/lib/perl5 directory of your home directory, so you then need to add this line to your Perl scripts:
use lib '/home/ex/example.com/perl5/lib/perl5';
So the complete script will now look like:
#!/usr/bin/perl use lib '/home/ex/example.com/perl5/lib/perl5'; use Text::Lorem; print Text::Lorem->new()->words(5);
After doing that, the script works.
Copyright © 2000-2023 Tiger Technologies LLC