How to Install Perl on Rocky Linux 10, 9 and 8

Install Perl on Rocky Linux 10, 9 and 8 using DNF or source compilation. Covers cpanm modules, updates, and removal steps.

UpdatedPublished AuthorJoshua JamesRead time7 minGuide typeRocky Linux

Rocky Linux keeps Perl tied to each major release, which is useful for stable admin scripts but not always enough when a project expects a newer interpreter. You can install Perl on Rocky Linux with DNF for a package-managed runtime, add CPAN tooling for modules such as LWP::Protocol::https, or compile the current Perl release from source when you need a separate custom tree.

DNF is the right default for most systems because updates arrive through normal Rocky Linux package maintenance. The source method stays isolated under /usr/local/perl-current and exposes perl-source, so it does not replace Rocky Linux’s package-managed /usr/bin/perl.

Install Perl on Rocky Linux

Start with the DNF method unless you already know a script, module, or application needs a newer Perl branch than Rocky Linux provides.

Choose a Perl Installation Method on Rocky Linux

MethodSourceBranchUpdatesBest Fit
DNF packageRocky Linux AppStreamDistribution defaultThrough dnf upgradeProduction systems, automation scripts, and module installs that should stay package-managed
Source buildPerl.org downloadsCurrent stable release resolved at install timeManual update-perl-source helperDevelopers who need a newer Perl branch, custom build options, or a separate interpreter for testing

Rocky Linux publishes different default Perl branches for each supported major release. This matters when a script specifies a minimum Perl version or when you compare DNF with a source build.

Rocky Linux ReleaseDefault Perl Package BranchRepositoryNotes
Rocky Linux 105.40.2AppStreamNewest packaged branch in the current Rocky Linux set
Rocky Linux 95.32.1AppStreamCommon branch for current Rocky Linux 9 server deployments
Rocky Linux 85.26.3AppStreamMaintenance-mode branch for older Rocky Linux 8 deployments

Refresh Rocky Linux Before Installing Perl

Refresh package metadata and review any pending system updates before adding Perl packages:

sudo dnf upgrade --refresh

Commands that start with sudo can ask for your account password and may change system packages. Review DNF transaction summaries before confirming installs, upgrades, or removals.

Install Perl with DNF on Rocky Linux

Install Perl with cpanminus, HTTPS support for LWP-based modules, and perldoc:

sudo dnf install perl perl-App-cpanminus perl-LWP-Protocol-https perl-Pod-Perldoc

The package names are intentionally explicit. perl-App-cpanminus provides cpanm, and perl-LWP-Protocol-https fixes HTTPS support for modules that use LWP::UserAgent.

Installing cpanminus also brings in Perl build helpers such as perl-ExtUtils-Install, perl-devel, make, and, on newer Rocky Linux releases, gcc. That is normal for CPAN module workflows because some modules compile XS or C code during installation.

These packages come from Rocky Linux BaseOS and AppStream, so the Perl workflow does not need EPEL, CRB, or PowerTools.

Verify the DNF Perl Installation

Check the Perl branch, cpanminus, and LWP HTTPS support. The sed command in Linux trims the cpanminus banner to the first two useful lines:

perl -e 'printf "%vd\n", $^V'
cpanm --version | sed -n '1,2p'
perl -MLWP::Protocol::https -e 'print "LWP HTTPS OK\n"'

Relevant output on Rocky Linux 10 includes:

5.40.2
cpanm (App::cpanminus) version 1.7047 (/usr/bin/cpanm)
perl version 5.040002 (/usr/bin/perl)
LWP HTTPS OK

Rocky Linux 9 reports 5.32.1, and Rocky Linux 8 reports 5.26.3. Those lower branch numbers are normal for their release streams.

Compile Perl from Source on Rocky Linux

Use source compilation only when the packaged branch is not enough. This workflow resolves the latest stable tarball from perl.org, verifies the SHA-256 checksum from CPAN, installs into a versioned prefix, and creates stable perl-source and cpan-source commands.

Install the source-build prerequisites:

sudo dnf install gcc make tar gzip curl coreutils

Create a reusable workspace under your home directory. Run the next few blocks in the same terminal session so the variables stay available:

mkdir -p "$HOME/src/perl-source-build"
cd "$HOME/src/perl-source-build"

Resolve the current stable source archive from perl.org. The grep command in Linux filters the download page to stable tarball filenames before the script builds the CPAN URL.

PERL_TARBALL="$(curl -fsSL https://www.perl.org/get.html | grep -oE 'perl-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' | head -n 1)"
if [ -z "$PERL_TARBALL" ]; then
  echo "Could not determine the latest Perl tarball from perl.org."
  exit 1
fi

PERL_VERSION="${PERL_TARBALL#perl-}"
PERL_VERSION="${PERL_VERSION%.tar.gz}"
PERL_PREFIX="/usr/local/perl-$PERL_VERSION"

printf 'Resolved Perl source: %s\n' "$PERL_TARBALL"
printf 'Install prefix: %s\n' "$PERL_PREFIX"

Download the archive and its checksum. The curl command in Linux handles both downloads here, while the archive itself is a gzip-compressed tarball.

curl -fLO --progress-bar "https://www.cpan.org/src/5.0/$PERL_TARBALL"
curl -fLo "$PERL_TARBALL.sha256" "https://www.cpan.org/src/5.0/$PERL_TARBALL.sha256"

Verify the SHA-256 checksum before extracting the source:

printf '%s  %s\n' "$(cat "$PERL_TARBALL.sha256")" "$PERL_TARBALL" | sha256sum -c -
perl-5.42.2.tar.gz: OK

Extract the archive, then enter the source directory. For more background on this archive format, see the gz and tgz extraction guide.

rm -rf "perl-$PERL_VERSION"
tar -xzf "$PERL_TARBALL"
cd "perl-$PERL_VERSION"

Configure and compile Perl into the managed prefix:

./Configure -des -Dprefix="$PERL_PREFIX"
make -j"$(nproc)"

Run the test suite before installing. It can take a while, but a clean run ends with a clear success line:

make test
All tests successful.

Install the compiled tree and create stable helper symlinks:

sudo make install
sudo ln -sfn "$PERL_PREFIX" /usr/local/perl-current
sudo ln -sfn /usr/local/perl-current/bin/perl /usr/local/bin/perl-source
sudo ln -sfn /usr/local/perl-current/bin/cpan /usr/local/bin/cpan-source

Verify the source-built interpreter without changing the system perl command:

/usr/local/bin/perl-source -e 'printf "%vd\n", $^V'
command -v perl-source
test -x /usr/local/bin/cpan-source && echo "cpan-source symlink OK"
5.42.2
/usr/local/bin/perl-source
cpan-source symlink OK

Use perl-source when you want the source-built interpreter and perl when you want Rocky Linux’s package-managed interpreter. Keeping both names separate avoids accidental changes to scripts that expect /usr/bin/perl.

Manage Perl Modules on Rocky Linux

Rocky Linux packages many Perl modules as RPMs. Prefer DNF for modules that AppStream provides, then use CPAN or cpanminus when you need a module that is not packaged or when a project requires a newer CPAN release.

Check Whether DNF Provides a Perl Module

Query module providers before installing from CPAN. This example checks the package that supplies LWP::Protocol::https:

dnf repoquery --whatprovides 'perl(LWP::Protocol::https)' --qf '%{name} %{evr} %{repoid}'

Relevant output on Rocky Linux 10 includes:

perl-LWP-Protocol-https 6.13-3.el10 appstream

Install the RPM package when DNF provides the module:

sudo dnf install perl-LWP-Protocol-https

Install CPAN Modules with cpanm

Use cpanm for modules that are not available through DNF or when an application specifically asks for the CPAN version. Replace Module::Name with the module you need:

sudo cpanm Module::Name

System-wide CPAN installs place files outside the RPM database. Keep a note of manually installed modules so you can reproduce them later, especially on production servers.

Use CPAN with Source-Built Perl

Modules for the source-built interpreter belong in the source tree, not under Rocky Linux’s package-managed Perl path. Use cpan-source when you need to install modules for perl-source:

cpan-source Module::Name

For discovery and documentation, MetaCPAN is the searchable CPAN index.

List and Locate Installed Perl Modules

List modules known to ExtUtils::Installed:

perl -MExtUtils::Installed -E 'say for ExtUtils::Installed->new->modules'

Find the path for a specific module with perldoc:

perldoc -l Carp
/usr/share/perl5/vendor_perl/Carp.pm

Verify Perl Scripts on Rocky Linux

A small script verifies the interpreter, shebang, permissions, and syntax checker in one pass.

cat > hello.pl <<'EOF'
#!/usr/bin/env perl
use strict;
use warnings;

print "Hello from Perl\n";
EOF

The #!/usr/bin/env perl shebang uses the first perl in your PATH. That keeps the script portable between DNF Perl, source-built Perl, and other controlled shell environments.

Make the script executable, then run it. The chmod command in Linux changes the file mode for this local script.

chmod +x hello.pl
./hello.pl
Hello from Perl

Check syntax without running the script body:

perl -c hello.pl
hello.pl syntax OK

Update Perl on Rocky Linux

Update DNF-Installed Perl

DNF-managed Perl updates with the rest of Rocky Linux. To refresh only the main Perl packages installed earlier, run:

sudo dnf upgrade --refresh perl perl-App-cpanminus perl-LWP-Protocol-https perl-Pod-Perldoc

If no newer packages are available, DNF ends with:

Nothing to do.
Complete!

Routine maintenance can use a normal full update instead:

sudo dnf upgrade --refresh

Update Source-Compiled Perl

Source-compiled Perl does not receive DNF security updates. Create a reusable helper so future updates repeat the same checksum, build, test, install, and symlink steps.

tmp_script="$(mktemp)"
cat > "$tmp_script" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

if [ "$(id -u)" -eq 0 ]; then
  echo "Run update-perl-source as a regular user; it uses sudo only for install steps."
  exit 1
fi

for cmd in curl grep tar gzip make gcc sha256sum nproc; do
  if ! command -v "$cmd" >/dev/null 2>&1; then
    echo "Missing required command: $cmd"
    echo "Install build tools with: sudo dnf install gcc make tar gzip curl coreutils"
    exit 1
  fi
done

WORKDIR="$HOME/src/perl-source-build"
mkdir -p "$WORKDIR"
cd "$WORKDIR"

PERL_TARBALL="$(curl -fsSL https://www.perl.org/get.html | grep -oE 'perl-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' | head -n 1)"
if [ -z "$PERL_TARBALL" ]; then
  echo "Could not determine the latest Perl tarball from perl.org."
  exit 1
fi

PERL_VERSION="${PERL_TARBALL#perl-}"
PERL_VERSION="${PERL_VERSION%.tar.gz}"
PERL_PREFIX="/usr/local/perl-$PERL_VERSION"
CURRENT_VERSION="$([ -x /usr/local/bin/perl-source ] && /usr/local/bin/perl-source -e 'printf "%vd", $^V' 2>/dev/null || true)"
CURRENT_VERSION="${CURRENT_VERSION:-none}"

echo "Current source Perl: $CURRENT_VERSION"
echo "Latest source Perl:  $PERL_VERSION"

if [ "$CURRENT_VERSION" = "$PERL_VERSION" ]; then
  echo "Already up to date."
  exit 0
fi

read -r -p "Build and install Perl $PERL_VERSION? [y/N] " confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
  echo "Update cancelled."
  exit 0
fi

rm -rf "perl-$PERL_VERSION" "$PERL_TARBALL" "$PERL_TARBALL.sha256"
curl -fLO --progress-bar "https://www.cpan.org/src/5.0/$PERL_TARBALL"
curl -fLo "$PERL_TARBALL.sha256" "https://www.cpan.org/src/5.0/$PERL_TARBALL.sha256"
printf '%s  %s\n' "$(cat "$PERL_TARBALL.sha256")" "$PERL_TARBALL" | sha256sum -c -

tar -xzf "$PERL_TARBALL"
cd "perl-$PERL_VERSION"
./Configure -des -Dprefix="$PERL_PREFIX"
make -j"$(nproc)"
make test
sudo make install
sudo ln -sfn "$PERL_PREFIX" /usr/local/perl-current
sudo ln -sfn /usr/local/perl-current/bin/perl /usr/local/bin/perl-source
sudo ln -sfn /usr/local/perl-current/bin/cpan /usr/local/bin/cpan-source

echo "Updated source Perl to:"
/usr/local/bin/perl-source -e 'printf "%vd\n", $^V'
EOF

Validate the helper script syntax, install it into /usr/local/bin, and confirm the short command is available:

chmod +x "$tmp_script"
bash -n "$tmp_script"
sudo install -m 755 "$tmp_script" /usr/local/bin/update-perl-source
rm -f "$tmp_script"
command -v update-perl-source
/usr/local/bin/update-perl-source

Run the helper from any terminal directory:

update-perl-source

When the source build is already current, the helper stops before downloading or compiling:

Current source Perl: 5.42.2
Latest source Perl:  5.42.2
Already up to date.

Avoid automating source builds with cron. Run update-perl-source manually so you can watch the checksum, compile, test, and install stages and stop if a dependency or test fails.

Remove Perl from Rocky Linux

Remove DNF-Installed Perl Packages

Remove the DNF-installed packages only if no local scripts or packages still depend on them:

DNF may need to remove packages that depend on Perl. Read the transaction summary carefully before confirming, especially on servers that run monitoring, backup, or administration scripts.

sudo dnf remove perl perl-App-cpanminus perl-LWP-Protocol-https perl-Pod-Perldoc

Confirm the named packages are gone:

rpm -q perl perl-App-cpanminus perl-LWP-Protocol-https perl-Pod-Perldoc

If perl-ExtUtils-Install, perl-devel, gcc, and make were installed only for Perl module builds and no other source builds need them, remove those tools separately after reviewing the transaction:

sudo dnf remove perl-ExtUtils-Install perl-devel gcc make

Remove Source-Compiled Perl

The source method uses a managed prefix and stable symlinks, so removal can target only the files created by the source workflow.

These commands permanently delete the source-built Perl prefix, perl-source, cpan-source, the update helper, and the reusable source-build workspace. Back up any modules or local work under those paths before continuing.

SOURCE_PREFIX="$(readlink -f /usr/local/perl-current 2>/dev/null || true)"
case "$SOURCE_PREFIX" in
  /usr/local/perl-[0-9]*)
    sudo rm -f /usr/local/bin/perl-source /usr/local/bin/cpan-source
    sudo rm -f /usr/local/perl-current
    sudo rm -rf "$SOURCE_PREFIX"
    ;;
  *)
    echo "No article-managed source Perl prefix found."
    ;;
esac

sudo rm -f /usr/local/bin/update-perl-source
rm -rf "$HOME/src/perl-source-build"

Refresh the shell command cache and confirm the source command is no longer available:

hash -r
command -v perl-source || echo "perl-source removed"

Remove CPAN User Caches

cpanminus and CPAN can leave build logs and downloaded archives under your home directory.

This cleanup permanently deletes your per-user CPAN caches. Keep them if you want old build logs for troubleshooting.

rm -rf "$HOME/.cpanm" "$HOME/.cpan"

Troubleshoot Perl on Rocky Linux

Fix perl: command not found

If perl -v returns bash: perl: command not found, install the DNF package for the normal system interpreter:

sudo dnf install perl

If you intentionally use the source-built interpreter instead, call its explicit command:

/usr/local/bin/perl-source -e 'printf "%vd\n", $^V'

Fix cpanm: command not found

If a module workflow expects cpanm, install the Rocky Linux package that provides it:

sudo dnf install perl-App-cpanminus

Then verify the command path:

command -v cpanm
/usr/bin/cpanm

Fix LWP HTTPS Module Errors

Errors such as Can't locate LWP/Protocol/https.pm in @INC or CPAN messages about HTTPS URL support usually mean the HTTPS transport module is missing. Install the AppStream package:

sudo dnf install perl-LWP-Protocol-https

Retest the module load after the package installs:

perl -MLWP::Protocol::https -e 'print "LWP HTTPS OK\n"'
LWP HTTPS OK

Fix Source Build Compiler Errors

If Configure reports that no C compiler is available, install the build tools:

sudo dnf install gcc make

Then return to the source directory and rerun the configure step:

cd "$HOME/src/perl-source-build/perl-$PERL_VERSION"
./Configure -des -Dprefix="$PERL_PREFIX"

If the variables are no longer set, rerun the resolver block from the source-build section before returning to the source directory.

Conclusion

Perl is ready on Rocky Linux as either a DNF-managed runtime or an isolated source build, with CPAN tooling available for module work. For source-based development, install Git on Rocky Linux to track scripts and patches, then use MetaCPAN when you need module documentation.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: