Today every Linux system mostly already ships Perl including a lot of modules. While this can be totally fine sometimes maybe you want to switch to a newer Perl version. Or maybe even an older version to test a module with an older Perl version for compatibility?

perlbrew is a tool that helps installing multiple Perl environments and gives you the ability to switch between them. Installing your own Perl also means you don’t mess with the system installed Perl and you are able to install any new module directly from CPAN. The Perl environments are managed in your $HOME directory.

First you need to install perlbrew itself. The best option is to install perlbrew from your system ressources if available. In Debian Bullseye you just can type

1
apt install perlbrew

It also installs dependency like gcc, make, patch and libc-dev that you need to compile your own Perl version. Maybe your favorite Linux distribution has a package too. If not you should at least install the same dependencies and maybe install App::perlbrew with the help of local::lib.

Once installed as a user (not root) you now can type.

1
perlbrew init

the command tells you to add a line to .profile (if you are using bash).

# Add perlbrew environment
source ~/perl5/perlbrew/etc/bashrc

You must add the line and then either restart the terminal or type the source command once.

To install the newest Perl version (at the point of writting this article) i did the following.

1
2
perlbrew install-patchperl
perlbrew install perl-5.36.0 -j 4

The -j 4 tells how many CPU cores should be used. This took around 4 minutes on my machine to compile Perl from source. After it is installed the new Perl version is installed but not used automatically. But you can now easily switch between Perl version with the perlbrew command.

You can see all installed Perl version with

1
2
user@machine:~$ perlbrew list
  perl-5.36.0

You can permanently switch to the new Perl version by executing.

1
2
3
user@machine:~$ perlbrew switch perl-5.36.0
user@machine:~$ perlbrew list
* perl-5.36.0

perlbrew list will mark the active Perl with a *. You also can check with perl --version if the correct version is being used.

You also can switch temporary just for the terminal session with

1
perlbrew use perl-5.36.0

Once the newest Perl version is installed i recommand to install App::cpanminus.

1
cpan App::cpanminus

Its up to you to install additional libraries as you need/want, here is a complete set of useful ones I installed.

 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
42
cpanm EV
cpanm AnyEvent
  cpanm Try::Tiny # if not explicitly installed Perl::LanguageServer will fail
  cpanm Perl::LanguageServer
cpanm Catalyst
cpanm Data::Printer
cpanm DBI
cpanm DBD::SQLite
cpanm SQL::Abstract
cpanm DBIx::Class
cpanm Text::Table
cpanm Term::ProgressBar
cpanm Moo
cpanm Moose
cpanm MooseX::StrictConstructor
cpanm Path::Tiny
cpanm Type::Tiny
cpanm Type::Tiny::XS
cpanm JSON::XS
cpanm Class::Accessor
cpanm Class::Accessor::Fast
  cpanm File::Copy::Recursive # if not explicitly installed; DateTime will fail
  cpanm Class::Tiny           # if not explicitly installed; DateTime will fail
  cpanm DateTime
cpanm Devel::NYTProf
cpanm Perl::Critic
cpanm Perl::Tidy
cpanm namespace::autoclean
cpanm LWP::UserAgent
cpanm WWW::Mechanize
cpanm Template
cpanm List::MoreUtils
cpanm List::MoreUtils::XS
cpanm Chart::Clicker
cpanm Curses
cpanm File::Slurp
cpanm IPC::Run
cpanm Devel::Symdump   # PerlNavigator
cpanm Sub::Util        # PerlNavigator
cpanm App::perlimports # PerlNavigator
cpanm PPI              # PerlNavigator
cpanm Class::Inspector # PerlNavigator

Don’t forget to use the following shebang line in your scripts.

#!/usr/bin/env perl

instead of directly picking a path to a specific perl version, or otherwise your scripts will not use your newly installed Perl.

Have fun coding!