Choose a different version or distribution
Introduction
Before we begin talking about how to install Perl in Debian 12, let's briefly understand – What is Perl?
Perl is a versatile and powerful programming language used for various tasks like web development, system administration, and data manipulation. Known for its flexibility and ease of use, Perl allows you to solve complex problems quickly and efficiently.
With its rich library of pre-built modules, Perl enables developers to write code that is reliable and scalable. Whether you're a beginner or an experienced programmer, Perl's wide adoption and extensive documentation make it a great choice for projects of all sizes.
In this tutorial, you will install Perl in Debian 12. We will also address a few FAQs on how to install Perl in Debian 12.
Advantages of Perl
- Versatility: Perl is a versatile programming language that excels in web development, system administration, and data manipulation.
- Simplicity: With its easy-to-understand syntax, Perl allows programmers to write code quickly and efficiently.
- Extensive libraries: Perl boasts a vast collection of pre-built modules that enhance productivity and enable rapid development.
- Scalability: Perl's flexible nature makes it suitable for projects of all sizes, from small scripts to large-scale applications.
- Community support: Perl has a thriving community that offers extensive documentation and active support, ensuring developers have access to valuable resources.
Install Perl on Debian 12 via APT
Step 1: Verify if Perl is Already Installed on Debian
It is wise to check if Perl is already installed on your Debian Linux system before installing it. Launch the terminal program and type the following command into it:
perl -v
The version number will show up if Perl is installed. In contrast, in the event that it is not installed, the terminal will display an error message.
Step 2: Refresh Debian Package Repository
It's crucial to update the package repository on your Debian Linux system to make sure you install the most recent version of Perl and all of its prerequisites. Run the following command:
sudo apt update
This command updates the local package index with the most recent details about available packages and their versions by establishing contact with the repository servers.
Step 3: Install Perl on Debian 12 via APT Command
After updating the package repository, you are ready to start the Perl installation. Put this command into action:
sudo apt install perl
Using this command, you can install the most recent version of Perl and its dependencies on your computer.
You may want to install extra packages for a more satisfying Perl developing experience. Among the well-known ones are:
perl-doc
: Includes reference guides, tutorials, and a variety of tools for learning and mastering Perl, which make up the official Perl documentation.libperl-dev
: Includes libraries and development files needed to compile and link Perl extensions and modules.libdbd-mysql-perl
: Simplifies interactions with MySQL through Perl scripts by providing a Perl interface to MySQL databases.libdatetime-perl
: A collection of modules that allow you to work with dates, times, and daylight saving time.libjson-perl
: Allows JSON data, which is frequently used in web applications, to be encoded and decoded.libxml-simple-perl
: Provides a straightforward Perl API for XML data parsing and manipulation.libtest-simple-perl
: An essential tool for guaranteeing code quality is a framework for creating and executing Perl unit tests.
Add the names of the additional packages to the apt install
command to install Perl with them. For instance, run the following to install Perl along with libdatetime-perl
and libjson-perl
:
sudo apt install perl libdatetime-perl libjson-perl
Step 4: Search For Additional Perl Packages on Debian
The Debian repositories contain many Perl packages. The apt-cache
command allows you to look for more packages. For example:
apt-cache search perl
All the available Perl packages are listed by this command. You can use the grep
command to narrow down your search. For instance, looking for MySQL-related packages:
apt-cache search perl | grep mysql
![Listing Perl MySQL-related packages on Debian Linux using the apt search command](https://www.linuxcapable.com/wp-content/uploads/2023/06/example-listing-perl-mysql-related-packages-on-debian-linux-via-apt-search-command.png)
Use the apt install
command after you've determined which package you want to install. Installing the libdbd-mysql-perl
package, for example:
sudo apt install libdbd-mysql-perl
The steps for installing Perl on Debian Linux were covered in this section, along with instructions on finding and installing more Perl packages. If the Perl version that comes with your Debian Linux release isn't what you need, you can install Perl by downloading the source code, as explained in section 2.
Install Perl on Debian 12 via the source
Step 1: Install Initial Packages on Debian For Perl
Make sure you have installed the required development tools and libraries on your Debian Linux system before starting to compile Perl from source. These are essential tools for the process of compilation. To install them, run the following command:
sudo apt install build-essential wget
Step 2: Download Perl Source on Debian
Downloading the Perl source code comes next, after the necessary dependencies have been installed. The source code is available on the official Perl website. Let's download Perl version 5.36.1 as an example for this tutorial. To obtain the source code, run the following command:
wget https://www.cpan.org/src/5.0/perl-5.36.1.tar.gz
Step 3: Extract Perl Source Code on Debian
Extracting the tarball is the next step after downloading the source code. The source code can be extracted by using the following command:
tar -xzf perl-5.36.1.tar.gz
Proceed to the directory where the extracted source code is located:
cd perl-5.36.1
Step 4: Configure Perl Build on Debian
Setting up the build process is crucial before beginning to compile the source code. By taking this step, you can be sure that Perl will be compiled with the features and options that work best for your system. Run the following command:
./Configure -des -Dprefix=/usr/local
This command tells Perl to be installed in the /usr/local
directory and configures the build with default settings.
![Successful configuration step of a Perl build on Debian](https://www.linuxcapable.com/wp-content/uploads/2023/06/example-successfully-configuring-perl-build-on-debian-linux.png)
Step 5: Compile and then Install Perl on Debian 12 via the source
You can now begin compiling the source code. Depending on how well your system is performing, this step may take some time. To begin the compilation, run the following command:
make
![Successful make-build process of Perl on Debian](https://www.linuxcapable.com/wp-content/uploads/2023/06/example-of-make-build-of-perl-on-debian-linux-successful.png)
After the compilation is finished, run the following commands to install Perl:
sudo make install
Step 6: Verifying Perl Installation on Debian
Let's confirm that Perl was installed correctly from the source at the end. Run the following command to find out the Perl version:
perl -v
The output of this command should be the Perl version number, indicating that the installation was successful.
![Perl version output on Debian Linux, confirming a successful installation from source](https://www.linuxcapable.com/wp-content/uploads/2023/06/example-of-perl-version-output-after-compiling-source-on-debian-linux-which-shows-successful-install.png)
You have total control over the configuration and compilation options when you install Perl from source. This approach is useful if you want to enable or disable specific features that aren't available in the pre-compiled packages from the Debian repositories, or if you need a specific version of Perl.
Test Perl: Create Perl Application for Testing Purposes on Debian 12
Step 1: Create Perl Script on Debian
Making a simple script allows you to confirm that Perl is operating correctly on your Debian Linux system. The output of this script will be "Hello, world!" to the terminal. To get started, open a terminal and type the following command to create a new file called hello.pl
and open it in the text editor Nano:
nano hello.pl
Enter the following Perl code into the Nano text editor:
#!/usr/bin/perl
print "Hello, world!\n";
This short code consists of a shebang line that defines the interpreter (Perl in this case) that will be used to run the script. The print
statement is used in the second line to output "Hello, world!" and a newline character.
Once the code has been entered, hit Ctrl + O
to save the file and Enter to confirm. Ctrl + X
can be used to exit Nano.
Step 2: Granting Execute Permissions to the Script
The script's permissions need to be changed in order for it to run. The chmod
command, which modifies the file's mode, is used to accomplish this. Execution rights are granted by the +x
flag. Run the following command:
chmod +x hello.pl
Step 3: Executing the Perl Script on Debian
Running the script is the last step after the required permissions have been set. Using the script file within the terminal, this is accomplished. Put in the following command:
./hello.pl
Your successful execution of the Perl script should be indicated by the terminal printing "Hello, world!".
This exercise checks that Perl runs on your Debian Linux system as intended and provides an overview of how to create and run a basic Perl script. This knowledge can be used as a starting point for more intricate scripting projects.
FAQs to Install Perl in Debian 12
How can I check the installed Perl version?
To check the installed Perl version in Debian 12, open the terminal and type perl -v
. The Perl version will be displayed in the output.
Does Debian 12 come with Perl pre-installed?
No, Perl is not included in the default installation of Debian 12. You will need to install it manually.
Are additional modules and libraries needed for Perl?
The core Perl installation is functional, but depending on your requirements, additional modules and libraries may be needed. These can be installed using package managers like CPAN or the system's package manager.
How do I execute a Perl script in Debian 12?
To execute a Perl script in Debian 12, open the terminal, navigate to the script's location, and run it using the perl script_name.pl
command.
Can I update Perl to a newer version?
Yes, you can update Perl in Debian 12 by following the instructions provided by the system's package manager or by referring to Perl's documentation for manual installation methods.
Will removing Perl affect other applications?
Removing Perl may affect other applications that depend on it. Make sure to verify the dependencies of other applications before uninstalling Perl.
Can I use a different version of Perl for specific projects?
Yes, you can use different versions of Perl for specific projects. Tools like perlbrew and plenv allow managing multiple Perl installations on your system, making it easier to switch between versions as per your project requirements.
Conclusion
We hope this tutorial helped you understand how to install Perl in Debian 12.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.