Installing perl with perlbrew
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
|
|
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.
|
|
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.
|
|
The -j 10
tells how many CPU cores should be used. This installs the new
Perl version but don’t use it as the default. You can now switch between Perl
version with the perlbrew
command.
You can see all installed Perl version with
|
|
You can permanently switch to the new Perl version by executing.
|
|
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
|
|
Once the newest Perl version is installed i recommand to install
App::cpanminus
.
|
|
Its up to you to install additional libraries as you need/want, here is a complete set of useful ones I installed (on Debian). First I usually install some system dependencies for C/C++ compiler and some headers for some libraries.
|
|
Then here some modules you maybe wanna try out.
|
|
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!