Jan 20, 2024 7 min read

How to Install Perl on Ubuntu 22.04

Install perl on ubuntu 22.04 with our step-by-step tutorial. It is a scripting language that can be used for variety of tasks like web creation.

Install Perl on Ubuntu 22.04
Install Perl on Ubuntu 22.04
Table of Contents

Introduction

Before we discuss how to install perl on ubuntu 22.04, let's first understand-What is Perl?

Perl is a versatile scripting language used for various purposes, including system administration, web development, and data manipulation. It has a rich ecosystem of modules and extensive community support. Installing Perl on Ubuntu 22.04 is a relatively straightforward process.

This tutorial will walk you through the steps of installing perl on ubuntu 22.04.

Advantages

  1. Versatile and Powerful: Perl offers a wide range of built-in features and modules that make it a powerful scripting language for various tasks.
  2. Text Processing Capabilities: Perl excels at handling text and provides robust tools for string manipulation, regular expressions, and pattern matching.
  3. Extensive Module Library: Perl has an extensive library of modules available via CPAN (Comprehensive Perl Archive Network), making it easy to leverage existing solutions for different programming tasks.
  4. Platform Agnostic: Perl is available on various operating systems, including Linux, Unix, macOS, and Windows. It allows developers to write once and run anywhere.
  5. Large and Active Community: Perl has a large and helpful community of developers who actively contribute to the language, offer support, and create useful resources.

Install Perl on Ubuntu 22.04 via APT

Step 1: Checking if Perl is Installed on Ubuntu

It's crucial to make sure Perl is already installed on your Ubuntu system before installing it. Open a terminal window and enter the following command to accomplish this:

perl -v

The version number of Perl will be displayed by the command if it is installed on your system. An error message will appear in the terminal if Perl is not installed.

Step 2: Update Ubuntu Before Perl Installation

You need to update the package repository on your Ubuntu system before installing Perl. By doing this, you can be sure that Perl and any dependencies it needs are downloaded at the most recent version. Use the following command to accomplish this:

sudo apt update

This command will update the package repository on your Ubuntu system.

Step 3: Install Perl on Ubuntu 22.04

Once you have updated the package repository on your Ubuntu system, you can install Perl using the following command:

sudo apt install perl

This command will download and install the latest version of Perl and any dependencies it requires.

Install Perl Additional Modules on Ubuntu

When installing Perl, add the names of these packages to the apt-get install command in order to install them. Run the following command, for example, to install Perl together with the libdatetime-perl and libjson-perl packages:

sudo apt install perl libdatetime-perl libjson-perl

The optional packages you provided will be installed along with Perl by using this command. Afterward, you can increase functionality and efficiency in your Perl scripts by utilizing these packages.

Search For Perl Modules on Ubuntu

There are a ton of additional Perl packages available on Ubuntu that you could find useful, in addition to the optional packages we have mentioned. The apt-cache program, which searches the Ubuntu package repository, can be used to look for more Perl software.

To use apt-cache to look for Perl packages, launch a terminal window and enter the following command:

apt-cache search perl

The packages for Perl that are available in Ubuntu's package repository will be listed after executing this command. The available packages are displayed by scrolling through the list, or you can use the grep command to look for a specific package.

For example, the following command can be used to look for packages associated with MySQL:

apt-cache search perl | grep mysql

A list of Perl packages having the term "mysql" in their name or description will be shown by using this command. Similar commands can be used to look for other keywords or particular packages that you might find useful.

Installing a package is as simple as using the apt-get command once you've located it. For instance, you can use the following command to install the libdbd-mysql-perl package that we previously discussed:

sudo apt install libdbd-mysql-perl

The software and any dependencies needed for it will be downloaded and installed by this command. The package can then be used as needed in your Perl programs.

Install Perl on Ubuntu 22.04 via source

The other way to install Perl that the guide will walk through is downloading the source archive, building the binary, and running it. If you require an updated or particular version of Perl, this approach can be the best option.

Step 1: Install Prerequisite Packages on Ubuntu

It's important to have the required development tools and libraries installed on your Ubuntu machine before starting the Perl installation process.

These are essential parts that make it easier to compile Perl straight from the source. Use the command below to install these required packages:

sudo apt install build-essential make wget

Step 2:Get Ubuntu's Perl Source Code

After setting up the requirements, download the source code for Perl. To get the most recent version of the code, visit the official Perl website. For the purpose of example, we will be using Perl version 5.38.0 in this tutorial.

Execute the subsequent command to obtain the designated version:

wget https://www.cpan.org/src/5.0/perl-5.38.0.tar.gz
💡
NOTE:The version used in the tutorial is provided as an example. To download the most recent version of the Perl source code, always visit the official website.

Step 3: Unpack Ubuntu's Perl Source Code

After the source code has been downloaded successfully, the tarball has to be extracted. To extract the source code, run the following command:

tar -xzf perl-5.38.0.tar.gz

Next, open the directory where the retrieved source code is stored:

cd perl-5.38.0

Step 4: Configure the Perl Build Settings on Ubuntu

Setting up the build setup is essential before starting the source code compilation process. This initial step configures the Perl compilation process to match the unique requirements and features of your Ubuntu system.

Execute the following command to set up the build:

./Configure -des -Dprefix=/usr/local
Setup Perl
💡
NOTE:Make sure to enter "-Dprefix" precisely as displayed, not just "-dprefix." This command sets /usr/local as the Perl installation directory and initializes the build using default options.

Step 5: Compile and Install Perl on Ubuntu

You are ready to compile the Perl source code now that the configuration is in place. This step's duration depends on how capable your system is. Use the command listed below to start the compilation process:

make
compile perl

After compilation is successful, run the following command to install Perl:

sudo make install

Step 6: Validate Perl Installation on Ubuntu

As a last step in the installation procedure, make that Perl has been installed correctly from the source. To see the installed version of Perl, run the following command:

perl -v
Version of Perl

By revealing the Perl version number, this command will confirm that the installation was successful.

Installing Perl from source gives you unmatched control over the compilation and configuration options. This method is especially helpful if your project needs a specific version of Perl or if you need to activate (or deactivate) features that aren't included in the pre-compiled packages that are accessible in the Ubuntu repositories.

Create a Perl Test on Ubuntu 22.04

To test Perl on your Ubuntu system, you can write a basic "Hello World" program. To execute the command, open a terminal window and type:

nano hello.pl

The following code can be entered in the Nano text editor once you run this command:

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

This code will print “Hello, world!” to the terminal.

Save the file by pressing Ctrl+O, then exit the editor by pressing Ctrl+X. To enable the script to run, use the following command:

chmod +x hello.pl

This command will make the script executable.

Now, run the script by typing the following command:

./hello.pl

The "Hello, world!" message will be printed to the terminal upon execution of the script.

FAQs to Install Perl on Ubuntu 22.04

Is Perl already installed on Ubuntu 22.04? 

No, Perl is not pre-installed on Ubuntu 22.04 by default. You need to install it using the package manager.

How can I run a Perl script? 

Save your Perl script with the .pl extension and run it using the perl command followed by the script's filename.

How do I install Perl modules? 

Perl modules can be installed from CPAN using the cpan or cpanm command-line tools. You can search for modules on CPAN's website (search.cpan.org) before installation.

Can I use Perl for web development? 

Yes, Perl can be used for web development. Popular web frameworks like Catalyst, Mojolicious, and Dancer provide the necessary tools and structures to build web applications.

Does Perl support object-oriented programming (OOP)? 

Yes, Perl supports object-oriented programming. It provides features such as classes, inheritance, polymorphism, and encapsulation.

Can I write GUI applications with Perl? 

Yes, Perl supports GUI development. Popular libraries like Tk and Gtk2 allow you to build graphical user interfaces using Perl.

Can I use Perl for system administration tasks? 

Yes, Perl is widely used for system administration due to its text processing capabilities, extensive modules, and ease of automating tasks.

Can Perl interoperate with other programming languages? 

Yes, Perl can be seamlessly integrated with other languages like C, C++, Python, and Java, allowing you to leverage existing code or libraries.

Conclusion

This tutorial explained how to install Perl on Ubuntu 22.04 Jammy Jellyfish. It provided two different installation techniques and then showed how to create and run a basic "Hello World" script to test Perl.

If you have any queries, feel free to ask them in the comments section, and we would be happy to respond to them....

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.