Perl and modules
You can now manage, as with other langages, your own repository for perl modules, using cpanminus
.
Note
cpanminus
and perlbrew
are already installed on the base system.
Using CPANminus
If you want to use the base system Perl (perl -V
), you only have to use cpanminus
. Configure it (to use ~/perl5.32/
) by running this command:
$ cpanm --local-lib=~/perl5.32 local::lib && eval $(perl -I ~/perl5.32/lib/perl5/ -Mlocal::lib)
If you have errors like /usr/bin/perl: symbol lookup error
and/or undefined symbol
, you may have a version mismatch (existing or old installation in your $HOME). Change the destination directory (~/perl5.32
), or erase the existing one.
You have to add, at the end of your ~/.bashrc
, these lines:
# PSMN11 / local cpanminus / force user's CPAN path
export PERL_MB_OPT="--install_base \"${HOME}/perl5.32\""
export PERL_MM_OPT="INSTALL_BASE=${HOME}/perl5.32"
export PERL5OPT="-I${HOME}/perl5.32/lib/perl5 -I${HOME}/perl5.32/lib/perl5/site_perl"
if [[ -d "${HOME}/perl5.32/lib/perl5" ]]; then
export PERL5LIB="${HOME}/perl5.32/lib/perl5:${PERL5LIB}"
fi
Then reload that file (source ~/.bashrc
) or disconnect/reconnect for it to modify your environment.
Install Perl modules
Every needed module can now be installed like this (ex: YAML::Tiny):
$ cpanm YAML::Tiny
Your installed modules are located in ${HOME}/perl5.32/lib/perl5
. See man cpanm
for more.
Install your own Perl
For more advanced users: You can build your own Perl. The simplest way is by using perlbrew
.
Initialize perlbrew
$ perlbrew init
perlbrew root (~/perl5/perlbrew) is initialized.
Then, as asked, add source ~/perl5/perlbrew/etc/bashrc
at the end of your ~/.profile
, then source your ~/.profile
(or disconnect-reconnect) for it to be loaded properly.
Note
You can change the default installation directory ($HOME/perl5/perlbrew
) to a group storage (see Where to store files?), if needed. See $PERLBREW_ROOT
in perlbrew man page.
Test it :
$ perlbrew version
/usr/bin/perlbrew - App::perlbrew/0.91
Warning
If you self-install
or upgrade
perlbrew, there will be two versions : your own, and the one already installed on the system (which remain active).
Install a version of Perl
$ perlbrew available
# perl
perl-5.35.8
perl-5.34.0
perl-5.32.1
perl-5.30.3
perl-5.28.3
[...]
Installation might take a while :
$ perlbrew install perl-5.35.8
[a certain amount of successfull logs]
Install a local CPANminus
First, select your own Perl installation:
$ perlbrew use 5.35.8
Install the cpanminus module with:
$ curl -L https://cpanmin.us | perl - App::cpanminus
Verify with these two commands:
$ perlbrew list-modules
App::cpanminus
$ which cpanm
/home/mylogin/perl5/perlbrew/perls/perl-5.35.8/bin/cpanm
Warning
You have now two versions of cpanminus
, the one from your perlbrew installation, and the one from the system (which remain active).
Add modules to your CPANm
Same as above, using the cpanminus
from your perlbrew
installation (ex: Log::Logger):
$ cpanm Log::Logger
Verify with:
$ perlbrew list-modules
App::cpanminus
Log::Logger
Warning
Do not install too many Perl versions (for space reasons), and use perlbrew clean
on a regular basis.
See this tutorial for more.