How to install Perl on RHEL 8 / CentOS 8 Linux

This article explains how to install and configure Perl in RHEL 8 / CentOS 8.

In this tutorial you will learn:

  • Perl Overview
  • Features of Perl
  • Download and Installation of Perl
  • Write and Execute Perl Program

Perl Features

Perl Features.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software Perl
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Perl Overview

Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.

The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). Its major features are that it’s easy to use, supports both procedural and object-oriented (OO) programming, has powerful built-in support for text processing, and has one of the world’s most impressive collections of third-party modules.

Features of Perl

The overall structure of Perl derives broadly from C. Perl is procedural in nature, with variables, expressions, assignment statements, brace-delimited blocks, control structures, and subroutines.

Perl also takes features from shell programming. All variables are marked with leading sigils, which allow variables to be interpolated directly into strings. However, unlike the shell, Perl uses sigils on all accesses to variables, and unlike most other programming languages that use sigils, the sigil doesn’t denote the type of the variable but the type of the expression. So for example, to access a list of values in a hash, the sigil for an array (“@”) is used, not the sigil for a hash (“%”). Perl also has many built-in functions that provide tools often used in shell programming (although many of these tools are implemented by programs external to the shell) such as sorting, and calling operating system facilities.

Perl takes lists from Lisp, hashes (“associative arrays”) from AWK, and regular expressions from sed. These simplify and facilitate many parsing, text-handling, and data-management tasks. Also shared with Lisp are the implicit return of the last value in a block, and the fact that all statements have a value, and thus are also expressions and can be used in larger expressions themselves.

Perl 5 added features that support complex data structures, first-class functions (that is, closures as values), and an object-oriented programming model. These include references, packages, class-based method dispatch, and lexically scoped variables, along with compiler directives (for example, the strict pragma). A major additional feature introduced with Perl 5 was the ability to package code as reusable modules.



All versions of Perl do automatic data-typing and automatic memory management. The interpreter knows the type and storage requirements of every data object in the program; it allocates and frees storage for them as necessary using reference counting (so it cannot deallocate circular data structures without manual intervention). Legal type conversions — for example, conversions from number to string — are done automatically at run time; illegal type conversions are fatal errors.

Download and Installation of Perl

In RHEL 8 / CentOS 8, Perl package is already included. You can check by using the below command to check if it installed or not.

# yum info perl 
# rpm -qa | grep perl
yum info perl
Updating Subscription Management repositories.
Updating Subscription Management repositories.
Available Packages
Name         : perl
Epoch        : 4
Version      : 5.26.2
Release      : 414.el8
Arch         : x86_64
Size         : 72 k
Source       : perl-5.26.2-414.el8.src.rpm
Repo         : rhel-8-for-x86_64-appstream-beta-rpms
Summary      : Practical Extraction and Report Language
URL          : http://www.perl.org/
License      : GPL+ or Artistic
Description  : Perl is a high-level programming language with roots in C, sed, awk and shell
             : scripting. Perl is good at handling processes and files, and is especially
             : good at handling text. Perl's hallmarks are practicality and efficiency.
             : While it is used to do a lot of different things, Perl's most common
             : applications are system administration utilities and web programming.
             : 
             : This is a metapackage with all the Perl bits and core modules that can be
             : found in the upstream tarball from perl.org.
             : 
             : If you need only a specific feature, you can install a specific package
             : instead. E.g. to handle Perl scripts with /usr/bin/perl interpreter,
             : install perl-interpreter package. See perl-interpreter description for more
             : details on the Perl decomposition into packages.

As you can see it is available but not installed hence you can install package perl by using the following command.

# yum install perl

Upon successful installation you will see the below output under “installed packages”

yum info perl
Updating Subscription Management repositories.
Updating Subscription Management repositories.
Last metadata expiration check: 0:02:57 ago on Wed 13 Mar 2019 11:26:36 PM +04.
Installed Packages
Name         : perl
Epoch        : 4
Version      : 5.26.2
Release      : 414.el8
Arch         : x86_64
Size         : 0.0  
Source       : perl-5.26.2-414.el8.src.rpm
Repo         : @System
From repo    : rhel-8-for-x86_64-appstream-beta-rpms
Summary      : Practical Extraction and Report Language
URL          : http://www.perl.org/
License      : GPL+ or Artistic
Description  : Perl is a high-level programming language with roots in C, sed, awk and shell
             : scripting. Perl is good at handling processes and files, and is especially
             : good at handling text. Perl's hallmarks are practicality and efficiency.
             : While it is used to do a lot of different things, Perl's most common
             : applications are system administration utilities and web programming.
             : 
             : This is a metapackage with all the Perl bits and core modules that can be
             : found in the upstream tarball from perl.org.
             : 
             : If you need only a specific feature, you can install a specific package
             : instead. E.g. to handle Perl scripts with /usr/bin/perl interpreter,
             : install perl-interpreter package. See perl-interpreter description for more
             : details on the Perl decomposition into packages.

After installation you can check the installed Perl version by using the command.



# perl -v
# perl -v

This is perl 5, version 26, subversion 2 (v5.26.2) built for x86_64-linux-thread-multi
(with 52 registered patches, see perl -V for more detail)

Copyright 1987-2018, 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.

Write and Execute Perl Program

Create the helloworld.pl program using editor like vim as shown below.

#!/usr/bin/perl

print "Hello World!";

Make sure perl interpreter is installed on your system as shown below.

# whereis perl
perl: /usr/bin/perl /usr/share/man/man1/perl.1.gz
# which perl
/usr/bin/perl

To run the program you can either execute using perl helloworld.pl or ./helloworld.pl.

# perl helloworld.pl 
Hello World!
# chmod +x helloworld.pl
# ./helloworld.pl 
Hello World!

You can also execute perl from the command line as shown below.



# perl -e 'print "Hello World!\n"'
Hello World!

Conclusion

Perl is going strong and will continue to grow in the nearby future. However, many beginners are deterred from becoming part of the Perl world, or understanding it, out of several defects in the online Perl community and resources.

Perl proves to be a gateway to UNIX for many people. Many people who start to use a UNIX-compatible system (like Linux or Solaris) write their shell-scripts in Perl, and later on actually learn shell programming. Many Windows people who used Perl for Win32, find the UNIX concept much more desirable afterwards. Perl is a reflection of UNIX in all so many ways, and I’d hate for someone to get scared of UNIX as a result of getting scared of Perl too.

You often hear people complaining at Perl’s briefness, difficulty to learn, “inconsistency”, “ugly syntax”, complexity, in-fix notation, size, dollar signs, insuitability for large codebases, etc. All these “issues” are very much marginal if not completely false in getting it into public acceptance. In fact it is a sign that it has a culture that not all people can accept, which is good, because not all people are the same in such ammoral issues as choice of programming language.

However, what can deter someone from learning Perl is a lack of good support and aid from an online community, which may be the only connection he has to this virtual world called “Perl”. Let’s change it.