This is step 2 in the Perl web development series. In this step we focus on setting up a new Perl environment with perlbrew so we can leave the system Perl alone. If you don’t care about messing with the system Perl or you already have a Perl setup you can skip this step.
I don’t like messing around with the system Perl. Sometimes the system Perl has tweaks specifically designed for the OS you’re working on and therefore can have unexpected behaviour. To deal with this I use perlbrew which is a very handy application that makes it possible to install multiple versions of Perl on your system so you can Play around with all versions.
Install perlbrew
Perlbrew is quitte easy to install. Run the following command and everything should be set. If you’re having troubles installing checkout out the perlbrew website for more install options.
$ \curl -L https://install.perlbrew.pl | bash
After installing run the perlbrew command to get a list of all the options.
$ perlbrew
Usage:
perlbrew command syntax:
perlbrew <command> [options] [arguments]
Commands:
init Initialize perlbrew environment.
info Show useful information about the perlbrew installation
install Install perl
uninstall Uninstall the given installation
available List perls available to install
lib Manage local::lib directories.
alias Give perl installations a new name
upgrade-perl Upgrade the current perl
list List perl installations
use Use the specified perl in current shell
off Turn off perlbrew in current shell
switch Permanently use the specified perl as default
switch-off Permanently turn off perlbrew (revert to system perl)
exec exec programs with specified perl enviroments.
self-install Install perlbrew itself under PERLBREW_ROOT/bin
self-upgrade Upgrade perlbrew itself.
install-patchperl Install patchperl
install-cpanm Install cpanm, a friendly companion.
install-multiple Install multiple versions and flavors of perl
download Download the specified perl distribution tarball.
clean Purge tarballs and build directories
version Display version
help Read more detailed instructions
Generic command options:
-q --quiet Be quiet on informative output message.
-v --verbose Tell me more about it.
See `perlbrew help` for the full documentation of perlbrew, or
See `perlbrew help <command>` for detail description of the command
Install a new Perl
After you have setup perlbrew its time to install a new Perl. Run the command to list all available Perl versions to check which one you want to install.
$ perlbrew available
perl-5.25.6
perl-5.24.0
perl-5.22.2
perl-5.20.3
perl-5.18.4
perl-5.16.3
perl-5.14.4
perl-5.12.5
perl-5.10.1
perl-5.8.9
perl-5.6.2
perl5.005_04
perl5.004_05
When you’ve found the one you want to install just simply run the install command and sit back and relax, this can take a while. Run a tail on the log to see the progress.
$ perlbrew install perl-5.23.8
Fetching perl 5.23.8 as /Users/***/perl5/perlbrew/dists/perl-5.23.8.tar.bz2
Download http://www.cpan.org/src/5.0/perl-5.23.8.tar.bz2 to /Users/***/perl5/perlbrew/dists/perl-5.23.8.tar.bz2
Installing /Users/***/perl5/perlbrew/build/perl-5.23.8 into ~/perl5/perlbrew/perls/perl-5.23.8
This could take a while. You can run the following command on another shell to track the status:
tail -f ~/perl5/perlbrew/build.perl-5.23.8.log
Use your new Perl
Your new Perl is installed so time to use it. You can either run programs using your new Perl by running the perlbrew exec command or permanently switch to the new Perl. In this series I choose the switch command.
$ perlbrew switch perl-5.23.8
Every time you run the perl command the new version is being used instead of the system Perl.
Install cpanm
We’re going to use a number of cpan modules and therefore need a good installer for the modules. Perlbrew works nicely with cpanm and even has a install command for it so this is the one we’ll use.
$ perlbrew install-cpanm
That’s it for step 2, our work here is done.