How to Install Perl on Fedora 40 or 39

Perl is a highly versatile and powerful programming language renowned for its proficiency in text manipulation and flexibility across various computing tasks. Its unique combination of features makes it an excellent choice for a wide range of applications, from quick scripting to large-scale projects.

Below are some of the key features of Perl:

  • Text Processing: Perl excels at regular expressions and string parsing, making it 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 various 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 proceed to the main article, we will demonstrate two methods to install Perl, depending on your requirements or preference for terminal commands.

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 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, 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.

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 in this case 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 actually 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, hit Enter to confirm, and exit 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

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.

Useful Links

Here are some valuable links related to using Perl:

  • Perl Official Website: Visit the official Perl website for information about the programming language, features, and the latest updates.
  • Perl Documentation: Access comprehensive documentation for detailed guides on using and programming with Perl.
  • Learn Perl: Explore learning resources, tutorials, and articles to help you start with Perl.
  • Perl Community: Join the Perl community to connect with other Perl developers, participate in discussions, and find support.
  • CPAN (Comprehensive Perl Archive Network): Visit the CPAN page for access to a vast collection of Perl modules and distributions.
  • MetaCPAN: Explore MetaCPAN for a modern interface to the CPAN repository, including advanced search features and module documentation.
  • CPAN Testers: Access the CPAN Testers website for information on the testing and quality assurance of CPAN distributions.
  • CPAN Request Tracker: Use the CPAN Request Tracker to report bugs, request features, and view issue tracking for CPAN modules.
  • Task::Kensho on MetaCPAN: Check out Task::Kensho, a collection of recommended modules for Perl programming, on MetaCPAN.
Joshua James
Follow me
Latest posts by Joshua James (see all)