How to Install Perl on Fedora 40/39/38 Linux

Perl, a highly versatile and powerful programming language, is renowned for its proficiency in text manipulation and its flexibility across various computing tasks. This guide will demonstrate how to install Perl on Fedora Linux, offering a straightforward approach for both beginners and experienced users. Perl’s unique combination of features makes it an excellent choice for a wide range of applications, from quick scripting to large-scale projects.

Key Features of Perl:

  • Text Processing: Excelling in regular expressions and string parsing, Perl is a go-to language for text analysis and manipulation.
  • Cross-platform Compatibility: Runs seamlessly on numerous operating systems, including Linux, Windows, and macOS.
  • Extensive CPAN Library: The Comprehensive Perl Archive Network (CPAN) provides a vast collection of modules for various functionalities.
  • Support for Multiple Programming Paradigms: Perl supports procedural, object-oriented, and functional programming, making it adaptable to various coding styles.
  • Easy Integration: Interoperability with other languages like C, C++, and Python, enhancing its utility in diverse environments.
  • Embedded Documentation: Perl supports embedded documentation, facilitating easy code maintenance and comprehension.

As we delve into the installation process on Fedora Linux, you’ll discover Perl’s simplicity in setup and its robustness in handling a multitude of tasks. This introduction paves the way for a practical, hands-on exploration of Perl, showcasing its capabilities and ease of integration into your programming toolkit.

Install Perl on Fedora Linux via DNF

Step 1: Verify if Perl is Already Installed on Fedora Linux

Before initiating the installation of Perl, it’s crucial to check if it’s already present on your Fedora Linux system. To do this, open a terminal and enter the command:

perl -v

This command checks for Perl’s presence and displays its version. If Perl is not installed, the terminal will show an error message, indicating that Perl needs to be installed.

Step 2: Refresh Fedora Package Repository

Updating your Fedora system’s package repository ensures that you get the latest version of Perl and its dependencies. Run the following command:

sudo dnf update --refresh

This command syncs your local package database with the online repository, providing up-to-date information about available packages and their versions.

Step 3: Install Perl on Fedora Linux via DNF Command

With the package repository refreshed, you can now install Perl. Use this command:

sudo dnf install perl

This will download and install the latest version of Perl along with any necessary dependencies on your Fedora system.

To enhance your Perl development environment, you might consider installing additional packages. Key packages include:

  • perl-doc: Contains extensive Perl documentation, including manuals and tutorials, vital for learning and mastering Perl.
  • perl-devel: Includes development tools and libraries essential for building Perl modules and extensions.
  • perl-DBD-MySQL: Provides an interface for Perl scripts to interact with MySQL databases.
  • perl-DateTime: Offers a comprehensive set of modules for handling dates and times, including support for time zones and daylight saving.
  • perl-JSON: Facilitates the encoding and decoding of JSON data, a common requirement in web applications.
  • perl-XML-Simple: Provides a straightforward API for parsing and manipulating XML data in Perl.
  • perl-Test-Simple: A framework for writing and executing Perl unit tests, crucial for maintaining code quality.

To install Perl with these additional packages, append their names to the dnf install command. For example, to install Perl along with perl-DateTime and perl-JSON:

sudo dnf install perl perl-DateTime perl-JSON
Terminal showing Perl installation via Fedora AppStream
Terminal output of Perl installation using Fedora Linux AppStream.

Step 4: Search For Additional Perl Packages on Fedora

Fedora’s repositories house a wide array of Perl packages. To explore these packages, use the dnf search command. For example:

sudo dnf search perl

This command lists all Perl-related packages in the repository. To narrow down your search, you can combine it with grep. For instance, to find packages related to MySQL:

sudo dnf search perl | grep mysql
DNF search for Perl packages on Fedora Linux
Using DNF to search for Perl packages on Fedora Linux.

When you find a specific package to install, use the dnf install command. For example, to install the perl-DBD-MySQL package:

sudo dnf install perl-DBD-MySQL

This section has guided you through the process of installing Perl on Fedora Linux and how to discover and install additional Perl packages. If the version of Perl available in your Fedora Linux distribution doesn’t meet your needs, refer to the next section below, which covers installing Perl from the source code.

Install Perl on Fedora Linux via the Source

Step 1: Install Development Tools and Libraries on Fedora Linux

Before compiling Perl from the source, it is essential to prepare your Fedora Linux system with the necessary development tools. These tools, including compilers and libraries, are critical for building software from source code.

Execute the following command to install a comprehensive set of development tools:

sudo dnf groupinstall "Development Tools" "Development Libraries"

This command ensures the installation of a suite of tools and libraries, such as GCC, make, and other utilities, laying the groundwork for a successful compilation process.

Installing development tools for Perl on Fedora Linux
Installing development tools and libraries for Perl on Fedora Linux.

Step 2: Download the Perl Source Code

Once your system is ready with the required tools, the next step is to download the Perl source code. Perl’s official website hosts the latest versions.

To download a specific version, for instance, Perl 5.38.0, use the wget command:

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

It’s important to note that the version mentioned here is an example. Always refer to the official Perl website to get the link for the latest version, ensuring you’re working with the most up-to-date and secure release.

Step 3: Extract the Perl Source Tarball

After downloading the source code, the next task is to extract it. The tarball (a .tar.gz file) contains the source files needed for installation.

Use the tar command to extract it:

tar -xzf perl-5.38.0.tar.gz

Then, change your directory to the newly created folder that contains the extracted files:

cd perl-5.38.0

Step 4: Configure the Perl Installation

Before compiling Perl, it’s vital to configure the build environment. This configuration step tailors the installation to your system’s specifics, ensuring optimal performance and compatibility.

Run the following and keep the command case sensitive:

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

The -des argument automatically selects default options for most settings, simplifying the configuration process. The -Dprefix option specifies the directory where Perl will be installed, which in this case is /usr/local, a standard location for software installed from source.

Terminal output of configuring Perl build on Fedora
Output after configuring the build settings for Perl.

Step 5: Compile and Install Perl on Fedora

Now it’s time to compile the source code. This step translates the Perl source into executable binaries tailored to your system.

Begin the compilation with:

make

Depending on your system’s specifications, this process might take some time. It’s a crucial phase where the source code is actually built into a runnable form.

Terminal output of 'make' command for Perl on Fedora
Terminal showing the ‘make’ command output for Perl.

Upon successful compilation, proceed to install Perl:

sudo make install

This command installs the compiled Perl binaries and libraries to the specified location in your system, making Perl ready for use.

Step 6: Verify the Perl Installation

Finally, ensure that Perl is correctly installed and ready for use. Verify the installation by checking the Perl version:

perl -v

This command displays the installed version of Perl, confirming the successful completion of the installation process.

Checking Perl version after installation on Fedora Linux
Terminal output showing Perl version check on Fedora Linux.

Create a Perl Test Application on Fedora Linux

Step 1: Create a Perl Script on Fedora Linux

To ensure Perl is working correctly on your Fedora Linux system, creating a basic script is a practical approach. This script will output a simple message to the terminal. Start by opening a terminal and use the following command to create a new file named hello.pl.

We’ll use the Nano text editor for this:

nano hello.pl

Inside Nano, input this Perl script:

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

This script starts with a shebang line, which tells the system that this script should be run with Perl. The print statement then outputs “Hello, world!” followed by a newline character.

Save your work in Nano by pressing Ctrl + O, hit Enter to confirm, and exit the editor with Ctrl + X.

Step 2: Grant Execute Permissions to the Script

To make the script executable, adjust its permissions with the chmod command. The +x flag is used to grant execution rights.

Run this command:

chmod +x hello.pl

This step changes the script’s mode, enabling it to be run as a program.

Step 3: Execute the Perl Script on Fedora Linux

Now that the script has the necessary permissions execute it by calling the file in the terminal:

./hello.pl

The output “Hello, world!” should appear in your terminal, confirming that your Perl script is running successfully.

This simple task verifies Perl’s functionality on your Fedora Linux system and introduces the basics of Perl scripting.

Conclusion

To wrap up, our guide explored two efficient pathways for installing Perl on Fedora Linux: using the DNF package manager and compiling directly from the source. These methods ensure that you can tailor the installation to your specific needs, whether you’re seeking the simplicity of DNF or the customization offered by a source-based install. Alongside the installation, we also demonstrated how to create and execute a basic Perl script, verifying the successful setup of your Perl environment.

Remember, regularly updating your system and staying informed about the latest Perl releases will help maintain a secure and efficient development environment. As you delve deeper into Perl, these foundational skills will serve as a valuable asset for your programming journey.

Leave a Comment