How to Install and Use Perl on Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

Perl, a high-level programming language renowned for its flexibility and robust text manipulation capabilities, was developed by Larry Wall and introduced in 1987.

Upon its release, this tool gained widespread popularity across various domains, notably in scripting, text processing, system administration, web development, and beyond.

Top MNC companies, such as Amazon, cPanel, Cisco, NASA, IMDB, Craigslist, Shutterstock, and more, continue to use Perl for various purposes.

In this article, you will learn how to install Perl on Linux and run your first Perl program.

Tutorial Details

DescriptionPerl Programming Language
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Internet RequiredYes

Key Features

There are several compelling reasons to consider using Perl, especially on Linux. Here are some key factors that might persuade you to use Perl in a Linux environment:

  • Cross-Platform: Perl is available on most operating systems, making it a versatile choice for scripting tasks on different platforms.
  • Text Processing: Perl excels at working with text data, making it a preferred language for tasks like parsing log files, generating reports, and processing textual information.
  • Modules and CPAN: Perlโ€™s vast ecosystem, available through CPAN, provides numerous reusable modules that swiftly address common issues, significantly accelerating the development.
  • System Administrator: Perl robust text processing and cross-platform compatibility make it a top choice for automating system administration tasks.
  • Web Development: Perl, though less common than languages like Python or PHP, played a significant role in earlier web development to build dynamic websites and applications.

Utilizing the powerful capabilities of Perl on Linux, you can harness its flexibility and robustness to the fullest extent.

How to Install Perl on Linux

Perl is quite popular and comes pre-installed in the majority of Linux distributions, primarily due to its widespread utilization within the backend of numerous Linux tools.

If itโ€™s not present in the distribution, you have two options for installation: use the system default package manager or compile and install from source. So, letโ€™s begin withโ€ฆ

Installing Perl from the Package Manager

Open your terminal and execute one of the following commands based on your Linux distribution:

$ sudo apt install perl                                                                                                  #For Debian or Ubuntu
$ sudo dnf install perl                                                                                                  #For Red Hat or Fedora
$ sudo pacman -S perl                                                                                                #For Arch or Manjaro
$ sudo zypper in perl                                                                                                   #For OpenSUSE

After the installation is complete, execute the following command to ensure itโ€™s accessible via the terminal:

$ perl -v


Checking the Perl version installed via the package manager

In the image above, youโ€™ll notice that Perl v5.34.0 is currently installed, but a more recent version, 5.38.0, is already available.

This was the scenario with Ubuntu. As for Red Hat, Fedora, or Arch, they all had Perl version 5.36.0 installed. If your systemโ€™s repository offers an outdated Perl version, proceed to install the latest Perl version from source with the following steps:

Installing Perl from Source

To install Perl from source, youโ€™ll need to follow a few additional steps. Letโ€™s begin withโ€ฆ

1. Download the latest Perl version straight from the official site:

Downloading the latest Perl version

2. Open your terminal and execute the appropriate command tailored to your Linux distribution. This will install the necessary development tools for compiling and installing Perl from source.

$ sudo apt install build-essential                                                                                #For Debian or Ubuntu
$ sudo dnf group install "Development Tools"                                                         #For Red Hat or Fedora
$ sudo pacman -S base-devel                                                                                    #For Arch or Manjaro
$ sudo zypper in -t pattern devel_basis                                                                    #For OpenSUSE

3. Go to the directory containing the downloaded Perl source, usually located at โ€œ~/Downloads/โ€œ. From there, run the command below to extract the contents of the tarball.

$ cd ~/Downloads/
$ tar -xzf perl-*.tar.gz


Extracting the content of the Perl tarball

4. Navigate to the extracted directory.

$ cd perl-*/


Changing the location to the extracted Perl directory

5. Configure and build Perl in your home directory. You can adjust the installation location by modifying the โ€œ-Dprefixโ€ option.

$ ./Configure -des -Dprefix=$HOME/perl


Configuring the Perl source

6. Prior to the actual installation, ensure the essential dependencies for Perl are installed.

$ make


Installing dependencies before Perl installation

7. Perform a dry run test to verify the fulfillment of essential Perl installation prerequisites, which might take a long time (optional).

$ make test


Performing a dry run test before installation

8. Execute the following command to setup and configure Perl from source:

$ make install


Installing the latest Perl from the source

9. Once youโ€™ve completed the aforementioned steps, add the following line to your shell configuration file, which could be โ€œ~/.bashrcโ€œ, and then refresh your terminal session to apply the changes.

export PATH=$HOME/perl/bin:$PATH


Adding the Perl directory to the shell configuration file

10. Run the following command to ensure the latest Perl version is installed from source:

$ perl -v


Checking the Perl version installed via the source

Congratulations on successfully installing the latest version of Perl on your Linux system!

How to Use Perl on Linux

Running a Perl program in Linux is straightforward; Iโ€™ll illustrate how to execute a Perl program using practical examples.

1. Begin by using your preferred text editor to create a text file. Name it โ€œhello.plโ€œ, ensuring the โ€œ.plโ€ extension is retained, while the filename itself can vary.

$ vim

2. Add the following Perl code to the file:

use strict;
use warnings;

print "Hello, world!\n";

Save and close the file.

3. To execute this Perl program, use the โ€œperlโ€ command, specifying the filename.

$ perl

You should see the output โ€œHello, world!โ€ printed to the terminal, as shown.

Running a basic Perl program in Linux

Thatโ€™s it! Youโ€™ve successfully created and executed a simple Perl program.

Final Word

I hope you find this article useful. If you have any questions or topic-related inquiries, please donโ€™t hesitate to ask them in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.