# PerlBrew On peut installer d'autres versions de Perl avec [**PerlBrew**](https://perlbrew.pl). Il faut au préalable installer **berkeley-db**, sans quoi il y aura une erreur à l'installer de Perl avec perlbrew. ```bash $ brew install berkeley-db ``` #### Installation de perlbrew: ```bash $ curl -L https://install.perlbrew.pl | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 170 100 170 0 0 245 0 --:--:-- --:--:-- --:--:-- 245 100 1554 100 1554 0 0 1935 0 --:--:-- --:--:-- --:--:-- 1935 ## Download the latest perlbrew ## Installing perlbrew Using Perl perlbrew is installed: ~/perl5/perlbrew/bin/perlbrew perlbrew root (~/perl5/perlbrew) is initialized. Append the following piece of code to the end of your ~/.bash_profile and start a new shell, perlbrew should be up and fully functional from there: source ~/perl5/perlbrew/etc/bashrc Simply run `perlbrew` for usage details. Happy brewing! ## Installing patchperl ## Done. ``` Pour zsh, on ajoute la ligne suivant à `.zshenv` ```bash source /Users/bruno/perl5/perlbrew/etc/bashrc ``` ##### Puis on installe la version de Perl que l'on veux: ```bash # Installer la dernière version de Perl: $ perlbrew install [options] stable # Installer une version précise de Perl: $ perlbrew install [options] 5.x.xx ``` ##### Liste des versions de Perl installées (dans $PERLBREW_ROOT): ```bash $ perlbrew list perl-5.30.1 ``` ##### On choisit la version que l'on veut utiliser: ```bash $ perlbrew use 5.30.1 -------------------------------------------------------------------------------- WARNING: zsh perlbrew sub-shell is not working on Mac OSX Lion. It is known that on MacOS Lion, zsh always resets the value of PATH on launching a sub-shell. Effectively nullify the changes required by perlbrew sub-shell. You may `echo $PATH` to examine it and if you see perlbrew related paths are in the end, instead of in the beginning, you are unfortunate. You are advised to include the following line to your ~/.zshenv as a better way to work with perlbrew: source /Users/bruno/perl5/perlbrew/etc/bashrc -------------------------------------------------------------------------------- A sub-shell is launched with 5.30.1 as the activated perl. Run 'exit' to finish it. silverbook% ``` Pour bash, on ajoute `source ~/perl5/perlbrew/etc/bashrc` au *~/.bash_profile*. Pour zsh, on ajoute `source /Users/bruno/perl5/perlbrew/etc/bashrc` au *~/.zshenv*. ##### Choisir la version de Perl dans le shell courant: ```bash # perlbrew use [perl- | | ] $ perlbrew use 5.30.1 $ which perl /Users/bruno/perl5/perlbrew/perls/perl-5.30.1/bin/perl $ perl -v This is perl 5, version 30, subversion 1 (v5.30.1) built for darwin-2level (with 1 registered patch, see perl -V for more detail) Copyright 1987-2019, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. ``` ##### Afficher la version courante de Perl: ```bash $ perlbrew use Currently using perl-5.30.1 ``` ##### Changer de version de Perl pour le shell courant et les futures sessions: ```bash # perlbrew switch [ ] $ perlbrew switch perl-5.30.1 # sans paramètre, affiche la version courante $ perlbrew switch Currently switched to perl-5.30.1 ``` ##### Désactiver temporairement perlbrew (dans le shell courant): ```bash # et reactiver le Perl par défaut $ perlbrew off ``` ##### Désactiver perlbrew: ```bash # et reactiver le Perl par défaut $ perlbrew switch-off # pour réactiver perlbrew $ perlbrew switch ``` ##### Créer un alias: ```bash $ perlbrew alias [-f] create $ perlbrew alias [-f] rename $ perlbrew alias delete ``` ##### Exécuter une commande pour chaque version de Perl installée: ```bash $ perlbrew exec perl -e 'print "Hello from $]\n"' $ perlbrew exec --with perl-5.12,perl-5.12-debug,perl-5.14.2 ``` ##### Variables d'environnement: ```bash $ perlbrew env unset PERLBREW_MANPATH export PERLBREW_PATH="/Users/bruno/perl5/perlbrew/bin" unset PERLBREW_PERL export PERLBREW_ROOT="/Users/bruno/perl5/perlbrew" export PERLBREW_VERSION="0.87" ``` ##### Installer cpanm: ```bash $ perlbrew install-cpanm ``` ##### Mettre à jour perlbrew: ```bash $ perlbrew self-upgrade ``` ##### Nettoyer les dossier d'installation et les archives: ```bash $ perlbrew clean Removing /Users/bruno/perl5/perlbrew/build/perl-5.30.1 Removing /Users/bruno/perl5/perlbrew/dists/perl-5.30.1.tar.gz Done ``` ##### Afficher la version de perlbrew: ```bash $ perlbrew version /Users/bruno/perl5/perlbrew/bin/perlbrew - App::perlbrew/0.87 ``` ##### Mettre à jour Perl: ```bash # met à jour les versions mineurs (5.14.0 -> 5.14.2) $ perlbrew upgrade-perl ``` ##### Télécharger Perl: ```bash # télécharger l'archive Perl $ perlbrew download perl-5.17.3 ``` ##### Liste des modules: ```bash $ perlbrew list-modules Modern::Perl ``` ##### Cloner les modules entre 2 versions de Perl: ```bash # perlbrew clone-modules $ perlbrew clone-modules 5.26.1 5.27.7 ``` #### Installer des modules: Avec perlbrew, on utilise **cpanm**: ```bash $ cpanm Modern::Perl --> Working on Modern::Perl Fetching http://www.cpan.org/authors/id/C/CH/CHROMATIC/Modern-Perl-1.20190727.tar.gz ... OK Configuring Modern-Perl-1.20190727 ... OK Building and testing Modern-Perl-1.20190727 ... OK Successfully installed Modern-Perl-1.20190727 1 distribution installed ``` Les modules sont installés ici: ``` /System/Volumes/Data/Users/bruno/perl5/perlbrew/perls/perl-5.30.1/lib/site_perl/5.30.1/darwin-2level/.meta/Modern-Perl-1.20190727 /System/Volumes/Data/Users/bruno/.cpanm/work/1576489302.28593/Modern-Perl-1.20190727 ``` ##### Mise-à-jour de cpanm: ```bash $ cpanm --self-upgrade It appears your cpanm executable was installed via `perlbrew install-cpanm`. cpanm --self-upgrade won't upgrade the version of cpanm you're running. Run the following command to get it upgraded. perlbrew install-cpanm ``` ##### N° de version: ```bash $ cpanm --V cpanm (App::cpanminus) 1.7044 on perl 5.030000 built for darwin-thread-multi-2level Work directory is /Users/bruno/.cpanm/work/1576565969.69495 You have make /usr/bin/make You have /usr/local/bin/wget You have /usr/bin/tar: bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.6 You have /usr/bin/unzip ```