Perl is an advanced programing language with over 26 years of development behind its belt, so I have decided to take it seriously and provide Perl tutorials on Jafty.com starting at the beginner level and progressing through more advanced Perl programming techniques.
Beginning with Perl
Perl does have different versions, but to keep it simple, we are going with the more popular stable version 5 of Perl. There is a version 6 of Perl, but it is a different language that is not yet as widely supported as version 5. Version 6 may have its own use cases that differ from version 5, but for most people’s needs, version 5 is currently preferred and probably will be for some time. That’s not saying that you shouldn’t check out version 6 also, just try version 5 first is what I am recommending for simplicities sake alone. There is also a version 4 that is quite outdated an no longer considered for serious new development use. Type “perl –version” at a command prompt to find out what version you have or read on for more detailed information.
Let’s get started by installing Perl. If you already have Perl installed, you may skip to the next tutorial, Writing your first Perl script. If you are not sure, read on and we will show you how to find out. Here is the basic process:
- check to see if Perl is installed. If it is, you can skip the rest of this tutorial and move on to writing your first Perl script.
- Check if gcc compiler is installed and if it is not, this is typically installed first. The other option is to install gcc and Perl simultaneously which we will get into later in this tutorial.
- Install Perl and gcc as needed.
- Write your first Perl script to test Perl.
How to Check for Perl Installation
Before you proceed to install Perl, you should make sure you don’t already have it because many servers come with it. The easiest way to check for Perl is to type “perl -v” at your command prompt from a shell console window. Here are example results if you do have it already:
[ec2-user@ip-172-30-0-9 ~]$ perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 25 registered patches, see perl -V for more detail)
Copyright 1987-2012, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using “man perl” or “perldoc perl”. If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
The first line above is the command prompt with only “perl -v” typed after it and the remaining lines are the response on a server with Perl 5 installed and working.
How to Install Perl
Here is a brief guide on installing latest stable version of Perl 5 on a Centos, Red Hat, Linux server. I did it on an Amazon cloud server, but the process is the same on any similar Linux flavor that supports YUM.
Check for GCC
As always before installing something on your server, check to make sure it is not installed already. I am always surprised to find something on my server that I didn’t know was there, but it does happen quite frequently. In the following example, the first line contains the command prompt followed by the command to check for the gcc compiler which is “gcc –version”. The remaining lines in brown text are the result of the gcc –version command in cases where gcc does exist on the server already:
[ec2-user@ip-172-30-0-9 ~]$ gcc –version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you did not get a similar response, then you need to install gcc for sure and most likely Perl too, so read on!
Installing a Developer Package using YUM
The easy way to get gcc and alot of other useful developer tools is to use YUM to install a group of software known as the Yum Developer Tools group. Available groups in Yum can be shown at the command line by typing “yum group list”. Here are actual results from my server:
In the above screenshot the Developer Tools group has already been installed. If you run this now before doing the install, Developer Tools will be listed under the “available groups” heading instead of the “installed groups” as you see here.
Installing gcc with Developer Tools is my recommendation because it could save you from installing other needed tools later. To install the Developer Tools group now, simply type this command into your shell:
sudo yum group install "Development Tools"
If for that didn’t work, I’ve heard that on some servers, you have to use yum groupinstall without the space. If the above failed use this:
sudo yum groupinstall "Development Tools"
Now if you type “gcc –version” you should see that gcc is installed!
Installing gcc by Itself
This method may be simpler to do, but doesn’t give you other useful tools a developer is likely to use. If you opt to simply install gcc quick and easy, just type this at the command prompt and you’re done:
yum install gcc*
That will install and update all necessary dependencies.
Now that you are sure to have gcc C compiler installed, it’s time to install Perl. The quick and easy way is to type this at the command prompt:
sudo yum install perl
If that doesn’t work, check out the other ways to install Perl using these links as it is a bit much to put here:
or this one:
Once you have made it to the end of this tutorial, you will have Perl up and running on your server. Now it is time to Write your first Perl script, so go here and do it now: http://jafty.com/blog/writing-your-first-perl-script/