How to Install Perl in Debian 12, 11 or 10

Perl is a versatile and robust programming language essential for various applications. If you need to install Perl on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster, it’s crucial to understand its enduring popularity and functionality.

Key Features of Perl:

  • Efficient Text Processing: Perl excels in text processing due to its powerful string manipulation syntax and superior handling of regular expressions. It provides a wealth of functions for pattern matching and text manipulation.
  • Extensive Repository & Modules: The Comprehensive Perl Archive Network (CPAN) is a vast repository filled with Perl modules, extending Perl’s core functionality seamlessly.
  • Cross-Platform & Community Support: Perl’s scripts run on various operating systems without modification, thanks to its platform independence. A vibrant, supportive community continually enriches Perl through contributions and support.
  • Flexibility & Practicality: Embracing the philosophy of “There’s more than one way to do it” (TIMTOWTDI), Perl offers flexibility in problem-solving and finds applications in diverse fields like web development, data munging, system administration, and bioinformatics.

With its powerful text-processing capabilities, extensive module repository, and supportive community, Perl is an invaluable asset for programmers. The following guide will walk you through the steps to install Perl on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster using the APT Package Manager and alternative installation methods.

Install Perl on Debian 12, 11, or 10 via APT

Step 1: Verify if Perl is Already Installed on Debian

Before installing Perl, verifying whether Perl is already installed on your Debian Linux system is prudent. Open a terminal window and execute the following command:

perl -v

If Perl is installed, the version number will be displayed. Conversely, the terminal will receive an error message if it is not installed.

Step 2: Refresh Debian Package Repository

To ensure that you install the latest version of Perl along with its required dependencies, it’s essential to refresh your Debian Linux system’s package repository. Execute the command below:

sudo apt update

This command contacts the repository servers and updates the local package index with the latest information about available packages and their versions.

Step 3: Install Perl on Debian 12, 11, or 10 via APT Command

Having updated the package repository, you can now proceed with installing Perl. Execute this command:

sudo apt install perl

This command fetches the latest version of Perl and its dependencies and installs them on your system.

For an enriched Perl development experience, you might want to consider installing additional packages. Some popular ones include:

  • perl-doc: Contains the official Perl documentation, which comprises reference manuals, tutorials, and an array of resources for learning and mastering Perl.
  • libperl-dev: Contains development files and libraries for compiling and linking Perl modules and extensions.
  • libdbd-mysql-perl: Facilitates a Perl interface to MySQL databases, streamlining interactions with MySQL through Perl scripts.
  • libdatetime-perl: A set of modules for manipulating dates and times, including support for time zones and daylight saving time.
  • libjson-perl: Enables encoding and decoding JSON data, commonly used in web applications.
  • libxml-simple-perl: Offers a simple API for parsing and manipulating XML data in Perl.
  • libtest-simple-perl: A framework for writing and running Perl unit tests, invaluable for ensuring code quality.

To install Perl with additional packages, include their names in the apt install command. For example, to install Perl with libdatetime-perl and libjson-perl, execute:

sudo apt install perl libdatetime-perl libjson-perl

Step 4: Search For Additional Perl Packages on Debian

There are numerous Perl packages available in the Debian repositories. You can search for additional packages by using the apt-cache command. For instance:

apt-cache search perl

This command lists all available Perl packages. You can refine your search by using the grep command. For example, searching for packages related to MySQL:

apt-cache search perl | grep mysql
Listing Perl MySQL related packages on Debian Linux using apt search command.
Screenshot demonstrating how to list Perl MySQL-related packages on Debian Linux using the apt search command.

Once you identify a package you wish to install, use the apt install command. For instance, installing the libdbd-mysql-perl package:

sudo apt install libdbd-mysql-perl

This section detailed the process of installing Perl on Debian Linux and how to search for and install additional Perl packages. If the Perl version available on your Debian Linux release is not what you require, you can see section 2, which explains how to install Perl by downloading the source.

Install Perl on Debian 12, 11, or 10 via the source

Step 1: Install Initial Packages on Debian For Perl

Before compiling Perl from the source, you must ensure that your Debian Linux system has the necessary development tools and libraries installed. These tools are vital for the compilation process. Execute the following command to install them:

sudo apt install build-essential wget

Step 2: Download Perl Source on Debian

After installing the required dependencies, the next step is to download the source code of Perl. You can obtain the source code from the official Perl website. For this tutorial, let’s download Perl version 5.36.1 as an example. Execute the following command to download the source code:

wget https://www.cpan.org/src/5.0/perl-5.36.1.tar.gz

Remember, the above command is just an example and will soon be outdated, ensure you do not forget to visit the link and grab the latest version.

Step 3: Extract Perl Source Code on Debian

With the source code downloaded, the next step is to extract the tarball. Use the following command to extract the source code:

tar -xzf perl-5.36.1.tar.gz

Now, navigate to the directory containing the extracted source code:

cd perl-5.36.1

Step 4: Configure Perl Build on Debian

Before compiling the source code, it’s essential to configure the build process. This step ensures that Perl will be compiled with the options and features that are most suitable for your system. Execute the following command:

./Configure -des -Dprefix=/usr/local

‘-Dprefix’ must be exact, do not use ‘-dprefix’.

This command configures the build with default settings and specifies that Perl should be installed in the /usr/local directory.

Successful configuration of Perl build on Debian Linux.
Screenshot depicting the successful configuration step of a Perl build on Debian Linux.

Step 5: Compile and then Install Perl on Debian 12, 11, or 10 via the source

Now, you’re ready to compile the source code. This step might take some time, depending on your system’s performance. Execute the following command to start the compilation:

make
Successful make build of Perl on Debian Linux.
Screenshot showing a successful make-build process of Perl on Debian Linux.

Once the compilation is complete, install Perl by executing the following:

sudo make install

Step 6: Verifying Perl Installation on Debian

Finally, let’s verify that Perl was successfully installed from the source. Execute the following command to check the version of Perl:

perl -v

This command should display the version number of Perl, confirming that the installation was successful.

Perl version output on Debian Linux showing successful installation.
Screenshot of Perl version output on Debian Linux, confirming a successful installation from source.

Installing Perl from the source gives you complete control over the configuration and compilation options. This method is beneficial if you need a specific version of Perl or wish to enable or disable particular features not available in the pre-compiled packages from the Debian repositories.

Test Perl: Create Perl Application for Testing Purposes on Debian 12, 11 or 10

Step 1: Create Perl Script on Debian

To verify the proper functioning of Perl on your Debian Linux system, it’s practical to create a rudimentary script. This script will merely output “Hello, world!” to the terminal. Begin by launching a terminal and entering this command to create a new file named hello.pl and open it using the Nano text editor:

nano hello.pl

In the Nano text editor, type the following Perl code:

#!/usr/bin/perl
print "Hello, world!\n";

This succinct code comprises a shebang line specifying the interpreter for running the script (Perl, in this case). The second line employs the print statement to output “Hello, world!” followed by a newline character.

After entering the code, save the file by pressing Ctrl + O and confirm by pressing Enter. To exit Nano, press Ctrl + X.

Step 2: Granting Execute Permissions to the Script

For the script to be executable, you need to modify its permissions. This is achieved with the chmod command, which alters the file’s mode. The +x flag bestows execution rights. Execute the following command:

chmod +x hello.pl

Step 3: Executing the Perl Script on Debian

With the necessary permissions set, the final step is to execute the script. This is done by invoking the script file within the terminal. Enter the following command:

./hello.pl

You should see “Hello, world!” printed on the terminal, indicating that your Perl script has been executed successfully.

This exercise validates that Perl functions as intended on your Debian Linux system and offers a glimpse into the construction and execution of a simple Perl script. The knowledge gained here can be applied as a foundation for more complex scripting endeavors.

Conclusion

This guide covered installing Perl on Debian Linux (versions 12 Bookworm, 11 Bullseye, and 10 Buster) through two methods: using the APT package manager for speed and building from the source for greater customization and control. We also explored the addition of optional packages to enhance Perl’s functionality. We created a basic Perl script, serving as a validation step and a starting point for newcomers to Perl programming. For experienced programmers, this process underscores Perl’s simplicity and power. Regularly update your system and Perl installation to benefit from the latest security and feature enhancements.