What Will I Learn?
- Installing the latest perl version in your local environment
- how to use perlbrew
- install perl modules
- how to start your first Modern::Perl project
You will need a Linux operating system. If you are unfamiliar with linux you can check out my latest guide on Howto setup virtual box with a debian linux image. I will make sure that the example works when using this base image, but of course you can use any distribution you like.
Perl might not be in favor in the latest years but there is actually still a lot of development and improvements being made. In order to use the latest features it’s useful to know how you can install the latest version of perl or even switch between different version.
Unfortunately perl is verry integrated in most linux distributions and replacing your system perl is not advisable. Also you can never be really sure what is included in your distribution and what is missing
There is a handy tool called Perlbrew wich allows you to be independent from the os perl release. As small preparation we will install some dependencies which come in handy later on:
sudo apt-get install curl vim git -y
Installing perlbrew itself
Now we install perlbrew. While you can also install this via cpan or other meen we will use the curl-pipe-sh way because it’s by far the easiest, won’t require root permissions or make us configure the original cpan command which is quite ugly.
curl -L https://install.perlbrew.pl | bash
This will download and setup the initial environment and install patchperl, a minimal version of perl wich can make sure that the following steps are based on the same requirements.
To make sure our shell will ideed find the perlbrew executable and everything is set up correctly, we have to execute the following:
echo "source ~/perl5/perlbrew/etc/bashrc" >> ~/.bashrc source ~/perl5/perlbrew/etc/bashrc
In order to see all currently available version of perl you can use the available command:
perlbrew available perl-5.27.8 available from <http://www.cpan.org/src/5.0/perl-5.27.8.tar.gz> perl-5.26.1 available from <http://www.cpan.org/src/5.0/perl-5.26.1.tar.gz> perl-5.24.3 available from <http://www.cpan.org/src/5.0/perl-5.24.3.tar.gz> perl-5.22.4 available from <http://www.cpan.org/src/5.0/perl-5.22.4.tar.gz> perl-5.20.3 available from <http://www.cpan.org/src/5.0/perl-5.20.3.tar.gz> perl-5.18.4 available from <http://www.cpan.org/src/5.0/perl-5.18.4.tar.gz> perl-5.16.3 available from <http://www.cpan.org/src/5.0/perl-5.16.3.tar.gz> perl-5.14.4 available from <http://www.cpan.org/src/5.0/perl-5.14.4.tar.gz> perl-5.12.5 available from <http://www.cpan.org/src/5.0/perl-5.12.5.tar.gz> perl-5.10.1 available from <http://www.cpan.org/src/5.0/perl-5.10.1.tar.gz> perl-5.8.9 available from <http://www.cpan.org/src/5.0/perl-5.8.9.tar.gz> perl-5.6.2 available from <http://www.cpan.org/src/5.0/perl-5.6.2.tar.gz> perl5.005_04 available from <http://www.cpan.org/src/5.0/perl5.005_04.tar.gz> perl5.004_05 available from <http://www.cpan.org/src/5.0/perl5.004_05.tar.gz> cperl-5.22.5 available from <https://github.com/perl11/cperl/archive/cperl-5.22.5.tar.gz> cperl-5.24.3 available from <https://github.com/perl11/cperl/archive/cperl-5.24.3.tar.gz> cperl-5.26.2 available from <https://github.com/perl11/cperl/archive/cperl-5.26.2.tar.gz> cperl-5.27.2 available from <https://github.com/perl11/cperl/archive/cperl-5.27.2.tar.gz>
Its noteworthy here how perl version numbers work. First we have the major number. You might have heard of perl6 but this has only very little to do with perl5 and we will not focus on it here.
Then we have the second version number (27,26,24… ). The stable releases are always even numbers. Odd numbers are experimental. This is the reason why when we talk of the latest version we currently take 5.26.1
The last version number indicates just minor releases, mostly security or performance related.
So to install the latest version we will do:
perlbrew install perl-5.26.1 Fetching perl 5.26.1 as /home/username/perl5/perlbrew/dists/perl-5.26.1.tar.bz2 Download http://www.cpan.org/src/5.0/perl-5.26.1.tar.bz2 to /home/username/perl5/perlbrew/dists/perl-5.26.1.tar.bz2 Installing /home/username/perl5/perlbrew/build/perl-5.26.1/perl-5.26.1 into ~/perl5/perlbrew/perls/perl-5.26.1 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.26.1.log perl-5.26.1 is successfully installed.
This will take a while and as shown on the screen you can open another terminal window and follow the installation with
tail -f ~/perl5/perlbrew/build.perl-5.26.1.log
You can exit the command again by pressing + c
The list of installed perl version can be found via the following command. We see that we only have one version installed currently which will be good for now. However if you read this in the future there might be newer version available.
perlbrew list perl-5.26.1 (installed on Wed Feb 7 08:27:12 2018)
Once all is done we can the activate the new perl version permanently for our user:
perlbrew switch perl-5.26.1
You can check if everything worked with
perl --version and 5.26.1 should be listed there.
I briefly touched at the beginning on the cpan tool which is perls default way of managing packages. There is far simpler way of installing perl packages wich is called cpanminus. Luckily perlbrew will set this up for us
And to finish everything up we will also install one module with it.
Why exactly this module? Its will let you easily enable some common sense features and declarations you should use when writing modern perl code. For more information check out the website where you can also read the book for free which touches on many aspects of writing modern perl code.
Posted on Utopian.io - Rewarding Open Source Contributors