HowTo setup a modern perl development environment

in #utopian-io6 years ago (edited)

perlbrew.png

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

Requirements

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.

Difficulty

  • Basic

Tutorial Contents

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.

Installing modules

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

perlbrew install-cpanm

And to finish everything up we will also install one module with it.

cpanm Modern::Perl 

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

Sort:  

Your contribution cannot be approved because it is not as informative as other contributions. See the Utopian Rules. Contributions need to be informative and descriptive in order to help readers and developers understand them.

  1. You MUST include more concepts in the tutorial. This is just installation process. I am not saying it is not useful. But for it to be acceptable as a utopian contribution, it needs lots of work. Thanks for the work.

You can contact us on Discord.
[utopian-moderator]

HI,

thanks for the feedback, ill keep improving ;) would a something be acceptable that shows how to write a module which interacts with the steem api?

best regards

This was really helpful for me, thank you!

You haven't made a post or comment in the past 7 days, and I want to reward you by upvoting you! So, respond to this, and then I'll be able to? :)

FYI ,this contribution was essential for me to get the accepted contribution to work. So, please at least link back to here, if you won't approve this one? (I really don't know how the approval process works -- just wanted to share that if I had only had the other link, I would be stuck.)

Hi,

im also not sure what to do here. I have a series of 3 tutorials and only the latest one was accepted. Its written in the rules that i cant include things in a curriculum section unless they are accepted. so i listed the links to here under the requirements section.
I dont think this post itself will be accepted since it was to simple, nevertheless its needed to set everything up and i wanted to keep the first stepps simple.

i guess the requirements link will have to do for now ;)

best regards
hoffmann

Yeah, it's like those StackOverflow top-rated answers which have a link to a site which is now dead. :(

At least your bread crumbs were there to help me! :)

Very informative. Thank you very much for sharing this. I find perl as one of the most convenient scripting languages. Its much better than native scripting languages like C-shell

Coin Marketplace

STEEM 0.28
TRX 0.11
JST 0.034
BTC 66540.93
ETH 3186.50
USDT 1.00
SBD 4.11