What's better than having Perl installed on your system? Having multiple Perls installed on your system! With Perlbrew you can do just that. But why—apart from surrounding yourself in Perl—would you want to do that?
The short answer is that different versions of Perl are… different. Application A may depend on behavior deprecated in a newer release, while Application B needs new features that weren't available last year. If you have multiple versions of Perl installed, each script can use the version that best suits it. This also comes in handy if you're a developer—you can test your application against multiple versions of Perl so that, no matter what your users are running, you know it works.
The other benefit is that Perlbrew installs to the user's home directory. That means each user can manage their Perl versions (and the associated CPAN packages) without having to involve the system administrators. Self-service means quicker installation for the users and gives sysadmins more time to work on the hard problems.
Install Perlbrew
The first step is to install Perlbrew on your system. Many Linux distributions have it in the package repo already, so you're just a dnf install perlbrew
(or whatever is the appropriate command for your distribution) away. You can also install the App::perlbrew
module from CPAN with cpan App::perlbrew
. Or you can download and run the installation script at install.perlbrew.pl.
To begin using Perlbrew, run perlbrew init
.
Install a new Perl version
Let's say you want to try the latest development release (5.27.11 as of this writing). First, you need to install the package:
perlbrew install 5.27.11
Switch Perl version
Now that you have a new version installed, you can use it for just that shell:
perlbrew use 5.27.11
Or you can make it the default Perl version for your account (assuming you set up your profile as instructed by the output of perlbrew init
):
perlbrew switch 5.27.11
Run a single script
You can run a single command against a specific version of Perl, too:
perlberew exec 5.27.11 myscript.pl
Or you can run a command against all your installed versions. This is particularly handy if you want to run tests against a variety of versions. In this case, specify Perl as the version:
perlbrew exec perl myscript.pl
Install CPAN modules
If you want to install CPAN modules, the cpanm
package is an easy-to-use interface that works well with Perlbrew. Install it with:
perlbrew install-cpamn
You can then install CPAN modules with the cpanm
command:
cpanm CGI::simple
But wait, there's more!
This article covers basic Perlbrew usage. There are many more features and options available. Look at the output of perlbrew help
as a starting point, or check out the App::perlbrew documentation. What other features do you love in Perlbrew? Let us know in the comments.
2 Comments