How to Install Perl on Fedora 40 or 39

Perl is a versatile and powerful programming language widely used for text processing, system administration, web development, and more. Known for its flexibility and extensive library of modules, Perl is a valuable tool for developers who need to write scripts for automation, data manipulation, and complex system tasks. On Fedora 40 or 39, installing Perl can be done through the command line using Fedora’s AppStream, which provides a stable and well-integrated version of Perl that meets most users’ needs.

For those who require the latest version or want more control over the installation process, an alternative option is to download, configure, and compile the Perl source code manually. This method allows you to customize the installation to suit specific requirements and ensures you are working with the most up-to-date version of Perl available. This guide will cover both methods, enabling you to choose the best approach for installing Perl on your Fedora system.

Method 1: Install Perl via DNF

Verify if Perl is Already Installed on Fedora

Before installing Perl, checking if it’s already present on your Fedora Linux system is crucial. 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.

Refresh the Fedora Package Repository

Updating your Fedora system’s package repository ensures 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.

Install Perl 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 and 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, which are vital for learning and mastering Perl.
  • perl-devel: Includes development tools and libraries 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.

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

sudo dnf install perl perl-DateTime perl-JSON

Search For Additional Perl Packages

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

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.

Method 2: Install Perl via Source Archive

Install Development Tools and Libraries

Before compiling Perl from the source, 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.

Download the Perl Source Code

Once your system is ready with the required tools, you can download the Perl source code. The latest versions are on Perl’s official website.

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

Note: 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.

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

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 is /usr/local, a standard location for software installed from source.

Compile and Install Perl

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

This process might take some time, depending on your system’s specifications. It’s a crucial phase in which the source code is built into a runnable form.

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.

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.

Create a Perl Test Application (Optional)

Create a Perl Script

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 outputs “Hello, world!” followed by a newline character.

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

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.

Execute the Perl Script

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

By successfully installing Perl on Fedora, either through the AppStream or by compiling the latest version from source, you’ve ensured that your system is equipped with a robust scripting language ready for a variety of tasks. The AppStream method provided a quick and reliable installation, ideal for most users, while the manual compilation approach offered greater flexibility and access to the latest features. It’s important to regularly check for updates, especially if you compiled Perl from source, to maintain security and performance. Always ensure that any dependencies are properly managed to avoid potential conflicts or issues in your development environment.

Leave a Comment