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: .. code-block:: bash $ 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: .. code-block:: bash # 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*): .. code-block:: bash $ 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 ~~~~~~~~~~~~~~~~~~~ .. code-block:: bash $ 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 :doc:`../filesystems/storages`), if needed. See ``$PERLBREW_ROOT`` in *perlbrew* man page. Test it : .. code-block:: bash $ 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 ~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: bash $ 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 : .. code-block:: bash $ perlbrew install perl-5.35.8 [a certain amount of successfull logs] Install a local CPANminus ~~~~~~~~~~~~~~~~~~~~~~~~~ First, select your own Perl installation: .. code-block:: bash $ perlbrew use 5.35.8 Install the cpanminus module with: .. code-block:: bash $ curl -L https://cpanmin.us | perl - App::cpanminus Verify with these two commands: .. code-block:: bash $ perlbrew list-modules App::cpanminus .. code-block:: bash $ 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*): .. code-block:: bash $ cpanm Log::Logger Verify with: .. code-block:: bash $ 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.