How to install Perl in Fedora Linux

See all Fedora Linux related FAQ
I am migrating an old Perl project from an unsupported OS to Fedora Linux 38. However, I discovered that Perl is not installed by default, while Python 3 is. This seems ridiculous. Anyway, here is how to install Perl in Fedora Linux including latest version of mod_perl with Apache (HTTPD) and get on with your life.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category Web Server
OS compatibility AlmaLinux CentOS Fedora RHEL Rocky Stream
Est. reading time 3 minutes

Installing Perl in Fedora Linux using the dnf command

  1. Log into the remote server using the terminal application provided by your operating system.
  2. First, patch the Fedora Linux server by running the following:
    # dnf update
    Outputs:

    Last metadata expiration check: 2:44:04 ago on Sun Oct 22 12:18:11 2023.
    Dependencies resolved.
    ===================================================================================
     Package               Architecture   Version                Repository       Size
    ===================================================================================
    Upgrading:
     iptables-libs         x86_64         1.8.9-4.fc38.1         updates         414 k
     librepo               x86_64         1.17.0-1.fc38          updates          96 k
     
    Transaction Summary
    ===================================================================================
    Upgrade  2 Packages
     
    Total download size: 510 k
    Is this ok [y/N]: y
    Downloading Packages:
    (1/2): librepo-1.17.0-1.fc38.x86_64.rpm            1.5 MB/s |  96 kB     00:00    
    (2/2): iptables-libs-1.8.9-4.fc38.1.x86_64.rpm     3.6 MB/s | 414 kB     00:00    
    -----------------------------------------------------------------------------------
    Total                                              2.4 MB/s | 510 kB     00:00     
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
      Preparing        :                                                           1/1 
      Upgrading        : librepo-1.17.0-1.fc38.x86_64                              1/4 
      Upgrading        : iptables-libs-1.8.9-4.fc38.1.x86_64                       2/4 
      Cleanup          : librepo-1.16.0-2.fc38.x86_64                              3/4 
      Cleanup          : iptables-libs-1.8.9-4.fc38.x86_64                         4/4 
      Running scriptlet: iptables-libs-1.8.9-4.fc38.x86_64                         4/4 
      Verifying        : iptables-libs-1.8.9-4.fc38.1.x86_64                       1/4 
      Verifying        : iptables-libs-1.8.9-4.fc38.x86_64                         2/4 
      Verifying        : librepo-1.17.0-1.fc38.x86_64                              3/4 
      Verifying        : librepo-1.16.0-2.fc38.x86_64                              4/4 
     
    Upgraded:
      iptables-libs-1.8.9-4.fc38.1.x86_64         librepo-1.17.0-1.fc38.x86_64        
     
    Complete!
  3. Now the server is patched, and up to date with all apps, it is time to search for Perl packages and modules offered by Fedora Linux. Run:
    # dnf list perl

    Last metadata expiration check: 2:39:16 ago on Sun Oct 22 12:18:11 2023.
    Available Packages
    perl.x86_64                        4:5.36.1-497.fc38                        updates

    Here is how to search for all packages:
    # dnf search perl
    # Regex search to narrow down results #
    # dnf search 'perl-*' | more
    # regex but with "grep" or "egrep" #
    # dnf search perl | grep -Ei 'Ajax|AWS'

    Here is output from the last command:

    Last metadata expiration check: 2:48:49 ago on Sun Oct 22 12:18:11 2023.
    claws-mail-plugins-perl.x86_64 : Perl based extended filtering engine for Claws Mail
    perl-CGI-Ajax.noarch : Perl-specific system for writing Asynchronous web applications
    perl-AWS-Signature4.noarch : Create a version4 signature for Amazon Web Services
  4. I wanted to see which Perl version Fedora was about to install, so I typed:
    # dnf info perl
    Look like I’m getting the Perl version 5.36.1:

    Last metadata expiration check: 2:40:11 ago on Sun Oct 22 12:18:11 2023.
    Available Packages
    Name         : perl
    Epoch        : 4
    Version      : 5.36.1
    Release      : 497.fc38
    Architecture : x86_64
    Size         : 14 k
    Source       : perl-5.36.1-497.fc38.src.rpm
    Repository   : updates
    Summary      : Practical Extraction and Report Language
    URL          : https://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.
  5. Okay, let us install the Perl. Type:
    # dnf install perl

    Click to enlarge

  6. To find out the version of Perl installed just now, simply type “perl -v” on the command line. For example:
    # perl -v
    Here is what my Fedora cloud Linux server displayed back:

     
    This is perl 5, version 36, subversion 1 (v5.36.1) built for x86_64-linux-thread-multi
     
    Copyright 1987-2023, 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 https://www.perl.org/, the Perl Home Page.
  7. The next step is to install an embedded Perl interpreter for the Apache web server as follows:
    # dnf install httpd mod_perl
  8. Edit the /etc/httpd/conf.d/perl.conf
    # vim /etc/httpd/conf.d/perl.conf
    Ensure that the following config exists:

    # Enable registry scripts for mod_perl #
    Alias /perl /var/www/perl
    <Directory /var/www/perl>
        SetHandler perl-script
        PerlResponseHandler ModPerl::Registry
        PerlOptions +ParseHeaders
        Options +ExecCGI
    </Directory>

    Create a new directory using the mkdir command and change directory using the cd command:
    # mkdir -v /var/www/perl
    # cd /var/www/perl

    Create the following hello.pl script for testing purpose:
    # vim hello.pl
    Append the following code:

    #!/usr/bin/perl
    print "Content-type: text/plain\n\n";
    print "This is a mod_perl 2.0 setup test by nixCraft.com\n";

    Finally, set executable bit on the script:
    # chmod +x -v hello.pl
    Test it using the browser or the CLI. For example:

    https://your-domain-com/perl/hello.pl

    OR from the server itself:

    {vivek@desktop~:}$ curl https://127.0.0.1/perl/hello.pl

    Click to enlarge

  9. Finally, I’m going to test and config mod_perl handlers. Here is how to test a response handler similar to the registry script. Create a new directory inside /var/www/perl called app1/
    # mkdir /var/www/perl/app1/
    Create a new file named /var/www/perl/app1/test.pm and add the following code:

    #file:app1/test.pm
    #----------------------
    package app1::test;
     
    use strict;
    use warnings;
     
    use Apache2::RequestRec ();
    use Apache2::RequestIO ();
     
    use Apache2::Const -compile => qw(OK);
     
    sub handler {
         my $r = shift;
     
         $r->content_type('text/plain');
         print "nixcraft.com mod_perl /app/ handler test!\n";
     
         return Apache2::Const::OK;
    }
    1;

    Create a new script /var/www/perl/startup.pl and set @INC path for your app. For example:

    use lib qw(/var/www/perl);
    1;

    Edit the /etc/httpd/conf.d/perl.conf and update as follows (append at the end):

    PerlRequire /var/www/perl/startup.pl
    <Location /app>
          SetHandler perl-script
          PerlResponseHandler  app1::test
    </Location>
    Restart the Apache (HTTPD) server using the systemctl command:
    # systemctl restart httpd
    Test it:

    {vivek@desktop~:}$ curl -I http://localhost/app/
    ##OR type in your browser##
    http://your-domain-com/app/

    Click to enlarge

How do I remove mod_perl and perl?

WARNING! The following command will remove Perl, configuration files, and all other related files. Always keep verified backups. The nixCraft or author is not responsible for data loss.
Simply run the dnf command:
# dnf erase httpd perl mod_perl

Conclusion

That is all for now. My perl is working, including mod_perl with Apache 2 under Fedora Linux. Please see Perl and mod_perl documentation here. Please note that this page provides instructions on installing and configuring mod_perl/perl to create and execute dynamic web pages. However, it is your responsibility to ensure your Perl application is secure. Web programming is vulnerable to various attacks, especially when your application deals with database queries, form submissions, sending emails, caching data, and other similar functionalities. Therefore, I recommend you refer to OWASP Web Security guides for complete information. Furthermore, it is highly advisable to protect your application from unwanted traffic using a web application firewall (WAF). Happy coding in Perl!

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Vivek Gite is an expert IT Consultant with over 25 years of experience, specializing in Linux and open source solutions. He writes about Linux, macOS, Unix, IT, programming, infosec, and open source. Follow his work via RSS feed or email newsletter.

Category List of Unix and Linux commands
AnsibleCheck version Fedora FreeBSD Linux Ubuntu 18.04 Ubuntu macOS
Archivingz commands
Backup ManagementDebian/Ubuntu FreeBSD RHEL
Database ServerBackup MySQL server MariaDB Galera cluster MariaDB TLS/SSL MariaDB replication MySQL Server MySQL remote access
Download managerswget
Driver ManagementLinux Nvidia driver lsmod
Documentationhelp mandb man pinfo
Disk Managementdf duf ncdu pydf
File Managementcat cp less mkdir more tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04 Ubuntu 24.04
KVM VirtualizationCentOS/RHEL 7 CentOS/RHEL 8 Debian 9/10/11 Ubuntu 20.04
Linux Desktop appsChrome Chromium GIMP Skype Spotify VLC 3
LXDBackups CentOS/RHEL Debian 11 Fedora Mount dir Ubuntu 20.04 Ubuntu 22.04
Modern utilitiesbat exa
Network ManagementMonitoring tools Network services RHEL static IP Restart network interface nmcli
Network UtilitiesNetHogs dig host ip nmap ping
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 11 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Power Managementupower
Package Managerapk apt-get apt yum
Processes Managementbg chroot cron disown fg glances gtop iotop jobs killall kill pidof pstree pwdx time vtop
Searchingag egrep grep whereis which
Shell builtinscompgen echo printf
System Managementreboot shutdown
Terminal/sshsshpass tty
Text processingcut rev
Text Editor6 Text editors Save and exit vim
User Environmentexit who
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami w
User Management/etc/group /etc/passwd /etc/shadow chsh
Web ServerApache Let's Encrypt certificate Lighttpd Nginx Security Nginx
WireGuard VPNAlpine Amazon Linux CentOS 8 Debian 10 Firewall Ubuntu 20.04 qrencode
2 comments… add one
  • Emmanuel Seyman Oct 31, 2023 @ 7:04

    You can install an rpm containing a Perl module without knowing its name.

    On Fedora, running the command ‘yum install "perl(CGI::Ajax)"‘ will install the rpm containing CGi::Ajax, regardless of what it is called.

    • 👮🛡️ Vivek Gite (Author and Admin) Vivek Gite Oct 31, 2023 @ 9:23

      That is nice. Thank you for sharing the tip.

Leave a Reply

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.