How to Install Perl on Fedora Linux

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 essential for developers who need to write scripts for automation, data manipulation, and complex system tasks. Common use cases include processing log files, managing system configurations, building web applications with CGI, and automating routine administrative tasks. As a result, by the end of this guide, you will have Perl installed on Fedora with your choice of stable repository packages or the latest features from source compilation.

Fedora Workstation and most spin variants include Perl by default for system scripts. In contrast, Fedora Server and minimal installations do not ship Perl pre-installed, though some packages may pull it in as a dependency. This guide covers two installation methods: using DNF for quick setup with automatic updates, and compiling from source for cutting-edge features and custom configurations. Choose the DNF method for most production environments, or compile from source when you need specific Perl versions or build optimizations.

Choose Your Perl Installation Method

Fedora offers two primary paths for installing Perl. The DNF package manager provides stable, tested versions with automatic security updates, while source compilation gives you access to the newest features and custom build options.

MethodChannelVersionUpdatesBest For
DNF Package ManagerFedora ReposStableAutomatic via dnf upgradeMost users who want tested packages with minimal maintenance
Source CompilationPerl.org DownloadsLatest stable or developmentManual recompilation requiredDevelopers needing cutting-edge features or custom builds

For most users, the DNF method is recommended because it provides automatic security updates and requires minimal maintenance. Only compile from source if you specifically need features unavailable in the repository version or require custom compilation flags.

Method 1: Install Perl via DNF

Check if Perl is Already Installed

Before installing Perl, first check if it’s already present on your Fedora system. Open a terminal and enter the command:

perl -v

If Perl is installed, you’ll see output like this:

This is perl 5, version 42, subversion 0 (v5.42.0) built for x86_64-linux-thread-multi
(with 15 registered patches, see perl -V for more detail)

Copyright 1987-2025, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

On the other hand, if Perl is not installed, the terminal will show a command not found error, indicating you need to proceed with installation.

Update Package Information

Before proceeding with the installation, updating your Fedora system’s package repository ensures you get the latest version of Perl and its dependencies. Run the following command:

sudo dnf upgrade --refresh

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

Install Perl and Optional Modules

Now that the package repository is refreshed, you can install Perl. Use this command:

sudo dnf install perl

This will download and install Perl and any necessary dependencies on your Fedora system.

Once the installation completes, verify Perl is working:

perl -v

You should see the installed version:

This is perl 5, version 42, subversion 0 (v5.42.0) built for x86_64-linux-thread-multi

Optional Perl Development Packages

Beyond the base installation, you can enhance your Perl development environment by 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. As an example, to install Perl along with perl-DateTime and perl-JSON:

sudo dnf install perl perl-DateTime perl-JSON

Find and Install Perl Modules from Repositories

Beyond the core installation, 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. For example, you might see available modules like:

perl-DBI.x86_64 : A database access API for Perl
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
perl-DateTime.x86_64 : Date and time object for Perl
perl-JSON.x86_64 : Parse and convert to JSON
perl-XML-Simple.x86_64 : Easy API to maintain XML
perl-Test-Simple.x86_64 : Basic utilities for writing tests

To further narrow down your search, you can combine it with grep. For instance, to find packages related to MySQL:

sudo dnf search perl | grep mysql

After finding 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

Install Modules from CPAN

While Fedora repositories provide many common modules, CPAN (Comprehensive Perl Archive Network) hosts thousands of community-contributed modules for specialized tasks like web frameworks, database interfaces, API clients, and text processing. Use CPAN when Fedora repositories do not package the module you need, or when you require a newer version than what DNF provides:

cpan Module::Name

Replace Module::Name with the actual module you need. As an example, to install the Email::Sender module:

cpan Email::Sender

First-time CPAN use triggers interactive configuration asking about mirror selection and build preferences. Press Enter repeatedly to accept defaults, which work fine for most users. Alternatively, if you want to skip this interactive setup entirely, add the -T and -i flags:

cpan -T -i Module::Name

The -T flag skips module tests (faster installation), and -i installs even if tests fail. Start with plain cpan Module::Name for your first installation so you see what the configuration questions look like; add the flags later if you want faster, non-interactive installs.

Some CPAN modules require C compilation. Ensure you have gcc and make installed (covered in the source compilation section) before installing complex CPAN modules.

Method 2: Install Perl via Source Archive

Install Development Tools and Libraries

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

Install essential build tools using Fedora’s package groups (pre-defined sets of related packages):

sudo dnf groupinstall "Development Tools" "Development Libraries"

The “Development Tools” group includes GCC (compiler), make (build automation), and related utilities. Following that, the “Development Libraries” group adds header files and libraries needed for compiling against system components. Together, these cover everything required for source compilation.

Download the Perl Source Code

With the development tools in place, you can now download the Perl source code.

You have two options for downloading the latest Perl source archive. You can use an automated command that always fetches the current version, or alternatively download manually if you prefer a simpler approach:

curl -s https://www.perl.org/get.html | grep -oP 'https://www\.cpan\.org/src/5\.0/perl-\d+\.\d+\.\d+\.tar\.gz' | head -1 | xargs wget

This automated approach saves you from manually checking version numbers each time Perl updates. Specifically, here is how it works:

  • curl -s: Silently fetches the Perl download page HTML
  • grep -oP: Extracts the tarball URL using regex
  • head -1: Takes the first match (latest stable version)
  • xargs wget: Downloads the tarball using the extracted URL

If the piped command syntax seems confusing, you can download manually instead: visit the Perl download page, find the .tar.gz link under “Download Latest Stable Source”, and copy the URL. Alternatively, run wget https://www.cpan.org/src/5.0/perl-X.XX.X.tar.gz with the actual version number. The automated command above simply does this lookup step for you.

Extract the Perl Source Tarball

Once the download finishes, extract the source archive:

tar -xzf perl-*.tar.gz

Then change to the extracted directory:

cd perl-*/

Configure the Perl Installation

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

Run the Configure script (case-sensitive) with recommended options:

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

The -des flag automatically accepts defaults for all configuration questions (without it, Configure prompts you interactively for dozens of settings). The -Dprefix=/usr/local flag specifies the installation directory; /usr/local is the standard location for software built from source, keeping it separate from system packages. These flags are optional shortcuts—running plain ./Configure works too but requires answering each prompt manually.

The configuration process will take a few minutes as it detects system features, compiler options, and installation paths.

Compile and Install Perl

After configuration completes, compile the source code. This step translates the Perl source into executable binaries tailored to your system:

make -j$(nproc)

The -j$(nproc) flag enables parallel compilation using all available CPU cores, significantly reducing build time. However, if this syntax seems confusing, you can run plain make instead (it will just take longer). The compilation process takes several minutes and displays progress through various Perl components and libraries.

Once compilation completes, install Perl:

sudo make install

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

Verify the Perl Installation

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

perl -v

You should see output confirming the compiled version:

This is perl 5, version 38, subversion 0 (v5.38.0) built for x86_64-linux

Copyright 1987-2023, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Verify Perl with a Hello World Script

Create a Perl Script

To ensure Perl is working correctly on your Fedora system, creating a basic script is a practical approach. This script will output a simple message to the terminal. First, open a terminal and create a new file named hello.pl:

We’ll use the Nano text editor for this:

nano hello.pl

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

After saving the script, you need to make it executable. To do this, adjust its permissions with the chmod command. The +x flag is used to grant execution rights.

Run this command:

chmod +x hello.pl

Next, verify the permissions were set correctly:

ls -l hello.pl
-rwxr-xr-x 1 user user 44 Nov 30 10:30 hello.pl

The x in the permissions indicates the file is now executable.

Execute the Perl Script

With the necessary permissions in place, execute the script by calling the file in the terminal:

./hello.pl

You should see this output:

Hello, world!

This output confirms that your Perl installation is working correctly and can execute scripts.

Troubleshooting Common Issues

Shebang Line Not Found Error

If your script fails with a “bad interpreter” error, check the shebang line matches your Perl installation location:

bash: ./hello.pl: /usr/bin/perl: bad interpreter: No such file or directory

This happens when the shebang points to the wrong Perl location. To fix it, first find where Perl is installed:

which perl

Depending on your installation method, the output will differ. For DNF installations, you’ll see:

/usr/bin/perl

However, for source installations, you’ll see:

/usr/local/bin/perl

Once you know the correct path, update your script’s first line to match it. As an alternative, use the portable shebang:

#!/usr/bin/env perl

As a result, this automatically finds Perl in your PATH regardless of installation method.

Missing Development Tools for Source Installation

If the Configure script fails with errors about missing compilers or tools:

sh: cc: command not found

This means development tools aren’t installed. To resolve this, install them:

sudo dnf groupinstall "Development Tools" "Development Libraries"

After installation completes, restart the configuration process from the extracted Perl directory.

CPAN Module Installation Failures

When installing CPAN modules fails with compilation errors, ensure you have both perl-devel and build tools:

sudo dnf install perl-devel gcc make

Many CPAN modules require C compilation support, so the perl-devel package provides the necessary headers and libraries for building Perl extensions.

CPAN Configuration Issues

If CPAN fails to configure or cannot download modules, first ensure perl-CPAN is installed:

sudo dnf install perl-CPAN

If you encounter mirror selection failures during first-time CPAN setup, reconfigure CPAN manually:

cpan

Then, at the CPAN shell prompt, run:

o conf init

This command restarts the configuration wizard. When prompted for mirror selection, choose automatic (option 1) so CPAN can select the fastest mirror.

Remove Perl from Fedora

Remove DNF-Installed Perl

If you installed Perl via DNF and need to remove it:

sudo dnf remove perl perl-*

Removing Perl may affect other packages that depend on it. However, DNF will show a list of dependent packages before removal. Review this list carefully as system tools may rely on Perl.

Remove Source-Compiled Perl

For Perl compiled from source (installed to /usr/local), remove the installation manually:

sudo rm -rf /usr/local/bin/perl*
sudo rm -rf /usr/local/lib/perl5/
sudo rm -rf /usr/local/share/man/man1/perl*
sudo rm -rf /usr/local/share/man/man3/

Additionally, remove the source directory if you still have it:

rm -rf ~/perl-5.38.0
rm -f ~/perl-5.38.0.tar.gz

Remove CPAN User Data

CPAN stores downloaded modules and configuration in your home directory. To remove this data:

rm -rf ~/.cpan/

This permanently deletes all locally downloaded CPAN modules and build artifacts. Back up any custom configurations in ~/.cpan/CPAN/MyConfig.pm before removing if you plan to reinstall Perl later.

Conclusion

You now have Perl installed via DNF package manager or compiled from source, with verification through a working Hello World script. Test your scripts with perl -c script.pl for syntax checking, explore CPAN for thousands of available modules, and use perldoc for built-in documentation on any function or module. For production deployments, document your module dependencies with cpanfile and use local::lib to install CPAN modules in your home directory instead of system-wide (run cpan App::cpanminus local::lib, then follow the shell setup instructions). Pair Perl with Git for version control or explore other programming languages like Go and Rust for system programming tasks.

Leave a Comment

Let us know you are human: