How to Install Perl on Debian (13, 12, 11)

Last updated Thursday, March 12, 2026 1:56 pm 12 min read

Perl still earns its place on Linux when you need fast text processing, quick admin scripts, or older applications that expect a mature runtime. Most people who install Perl in Debian only need the package from Debian’s default APT sources, while a source build makes sense when you need the newest upstream release.

On Debian, the package name is simply perl, and many add-on modules use the lib...-perl naming pattern. Many Debian systems already include Perl, while some minimal images keep only perl-base, so start by checking what is installed before you add the full package and CPAN tools. After installation, you can run scripts, add modules, and decide whether Debian’s packaged branch or a separate /usr/local build fits your workflow.

Install Perl on Debian

Debian’s default APT sources currently provide Perl 5.40.1 on Debian 13, 5.36.0 on Debian 12, and 5.32.1 on Debian 11. Perl.org currently lists 5.42.1 as the latest stable source release, so the packaged version is the safer default and the source build is the better fit only when you need newer upstream Perl.

MethodChannelVersionUpdatesBest For
APT packageDebian package indexDistribution defaultAutomatic via APTMost servers and workstations
Source buildPerl.org source downloadsLatest stableManual rebuildNewer upstream Perl or a separate /usr/local install

APT is the right default on most systems because it keeps Perl aligned with Debian packages and security updates. Build from source only when the packaged branch is too old for your project or you deliberately want a separate runtime under /usr/local.

Install Perl from Debian APT Sources

Start with Debian’s packaged Perl unless you already know you need the newer upstream build.

Check the Existing Perl Installation on Debian

Check whether Debian already has a Perl interpreter available:

perl -v | head -2
This is perl 5, version 40, subversion 1 (v5.40.1) built for x86_64-linux-gnu-thread-multi

If this prints a version but cpan is missing, keep going. Debian can provide the interpreter through perl-base without installing the full perl package.

Update the Debian Package Index for Perl

Refresh APT metadata before installing the full package:

sudo apt update

If your account does not have sudo access yet, set that up first with add a user to sudoers on Debian.

Install the Perl Package on Debian

Install Debian’s full Perl package and its standard tooling:

sudo apt install perl

Verify the installed version after APT finishes:

perl -v | head -2
This is perl 5, version 40, subversion 1 (v5.40.1) built for x86_64-linux-gnu-thread-multi

On Debian 12 the same check reports v5.36.0, and on Debian 11 it reports v5.32.1.

Debian packages many common extras separately, so you can keep the base install small and add only what your scripts need.

  • perl-doc adds the standard language manuals and reference pages.
  • libperl-dev installs headers and development files for native extensions.
  • libjson-perl handles JSON parsing and serialization.
  • libdatetime-perl adds higher-level date and time handling.
  • libdbd-mysql-perl adds DBI access for MySQL and MariaDB.

For example, this installs Perl with the documentation, development headers, and a common JSON module:

sudo apt install perl perl-doc libperl-dev libjson-perl

Find Additional Perl Modules in Debian

Debian names most repository modules with the lib...-perl pattern, so a targeted search is usually faster than scanning the full package list. The grep command guide explains the filtering step in more detail if you want it.

apt-cache search perl | grep mysql
libclass-dbi-mysql-perl - extensions to Class::DBI for MySQL
libcrypt-mysql-perl - Perl module to emulate the MySQL PASSWORD() function
libdatetime-format-mysql-perl - module to parse and format MySQL dates and times
libdbd-mysql-perl - Perl5 database interface to the MariaDB/MySQL database
libdbix-bulkloader-mysql-perl - Perl extension for MySQL bulk loading
libmysql-diff-perl - module for comparing the table structure of two MySQL databases
libtime-piece-mysql-perl - module adding MySQL-specific methods to Time::Piece

Install a matching module once you find the package you need:

sudo apt install libdbd-mysql-perl

Compile Perl from Source on Debian

Compile Perl from source when you need Perl 5.42.1 now or want it isolated under /usr/local instead of replacing Debian’s packaged files.

Install Perl Build Dependencies on Debian

Install the compiler toolchain and the libraries Perl detects during configuration:

sudo apt install build-essential curl libgdbm-dev libdb-dev libgdbm-compat-dev zlib1g-dev
  • build-essential provides gcc, make, and the rest of the core build toolchain.
  • curl fetches the latest stable tarball without hardcoding a version.
  • libgdbm-dev and libgdbm-compat-dev add GDBM and NDBM support.
  • libdb-dev and zlib1g-dev add Berkeley DB and compression support.

Create a Perl Build Workspace on Debian

Keep the source tree and update files under your home directory so future updates and removal stay manageable:

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

The $HOME variable expands to your own home directory, so this keeps the build files under your account instead of scattering them across system paths.

Download the Latest Perl Source on Debian

Download the current stable tarball directly from Perl.org without hardcoding the version number:

TARBALL="$(curl -fsSL https://www.perl.org/get.html | grep -oE 'perl-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' | head -n 1)"
curl -fLO --progress-bar "https://www.cpan.org/src/5.0/$TARBALL"
printf 'Tarball: %s\n' "$TARBALL"

This pipeline uses the curl command guide to read Perl.org and the grep command guide to isolate the current tarball name. Keep using the same terminal session because the checksum and extraction steps reuse the $TARBALL variable.

Tarball: perl-5.42.1.tar.gz

If you prefer a manual download, open the Perl.org download page, download the current stable tarball yourself, and set TARBALL to that filename before continuing.

Verify the Perl Tarball Checksum on Debian

CPAN publishes a separate SHA256 file for the Perl tarball. That sidecar file contains only the hash value, so the command below turns it into the format sha256sum -c expects.

CHECKSUM_FILE="${TARBALL}.sha256.txt"
curl -fLO --progress-bar "https://www.cpan.org/src/5.0/$CHECKSUM_FILE"
EXPECTED="$(tr -d '\n\r' < "$CHECKSUM_FILE")"
printf '%s  %s\n' "$EXPECTED" "$TARBALL" | sha256sum -c -
perl-5.42.1.tar.gz: OK

Extract the Perl Source Tree on Debian

Derive the source directory from the tarball name before extracting it, so you land in the correct folder even after future version bumps:

SOURCE_DIR="${TARBALL%.tar.gz}"
printf 'Source dir: %s\n' "$SOURCE_DIR"
tar -xzf "$TARBALL"
cd "$SOURCE_DIR"
Source dir: perl-5.42.1

Configure the Perl Build on Debian

Configure Perl to accept the standard defaults and install the source build under /usr/local, which keeps it separate from Debian’s packaged Perl under /usr/bin:

./Configure -des -Dprefix=/usr/local
Now you must run 'make'.

If you compile perl5 on a different machine or from a different object
directory, copy the Policy.sh file from this object directory to the
new one before you run Configure -- this will help you with most of
the policy defaults.

Build Perl on Debian

Compile the source tree before you run the test suite:

make
Everything is up to date. Type 'make test' to run test suite.

Run the Perl Test Suite on Debian

Run the upstream test suite before installing anything into /usr/local:

make test
All tests successful.
Elapsed: 535 sec
u=2.95  s=3.81  cu=236.25  cs=53.23  scripts=2672  tests=1339159

The elapsed time varies with CPU speed, but the success line should still read All tests successful.

Install the Source-Built Perl on Debian

Install the compiled tree and save the installed file list to a log that you can reuse later for removal:

sudo make install | tee "$HOME/perl-build/perl-install.log"

The tee command writes a copy of the install output to $HOME/perl-build/perl-install.log while still printing the installed paths on screen.

Verify the Source-Built Perl on Debian

Check which Perl binary your shell now prefers and confirm the upstream version. The which command guide explains the PATH lookup if you want more detail.

which perl
perl -v | head -2
/usr/local/bin/perl

This is perl 5, version 42, subversion 1 (v5.42.1) built for x86_64-linux

Debian’s default interactive PATH already places /usr/local/bin before /usr/bin, so the source build becomes the active perl without editing .bashrc.

When you add modules for this build, use /usr/local/bin/cpan so the source-built runtime keeps its own modules under /usr/local/lib/perl5 instead of mixing with Debian’s packaged Perl tree.

Update Source-Built Perl on Debian

APT updates the packaged Perl automatically, but a source build under /usr/local needs a manual rebuild when Perl.org publishes a new stable release.

Create the Perl Update Script on Debian

Keep the update script in the same build workspace so it can reuse your logs and source tree:

nano "$HOME/perl-build/update-perl.sh"

Paste in this script:

#!/usr/bin/env bash
set -euo pipefail

INSTALL_PREFIX="/usr/local"
BUILD_DIR="$HOME/perl-build"
LOG_FILE="$BUILD_DIR/perl-update.log"
INSTALL_LOG="$BUILD_DIR/perl-install.log"

for cmd in curl gcc make sha256sum; do
    if ! command -v "$cmd" >/dev/null 2>&1; then
        echo "Install the build prerequisites first:"
        echo "sudo apt install build-essential curl libgdbm-dev libdb-dev libgdbm-compat-dev zlib1g-dev"
        exit 1
    fi
done

CURRENT_VERSION=$($INSTALL_PREFIX/bin/perl -v 2>/dev/null | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || echo "none")
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 "$TARBALL" ]; then
    echo "Could not determine the latest Perl tarball from perl.org."
    exit 1
fi

LATEST_VERSION=${TARBALL#perl-}
LATEST_VERSION=${LATEST_VERSION%.tar.gz}

echo "Current version: $CURRENT_VERSION"
echo "Latest version:  v$LATEST_VERSION"

if [ "$CURRENT_VERSION" = "v$LATEST_VERSION" ]; then
    echo "Perl is already up to date."
    exit 0
fi

mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"

echo "$(date): Starting update to v$LATEST_VERSION" >> "$LOG_FILE"

find "$BUILD_DIR" -maxdepth 1 -type d -name 'perl-[0-9]*' -exec rm -rf {} +
rm -f perl-[0-9]*.tar.gz perl-[0-9]*.tar.gz.sha256.txt
curl -fL --retry 3 --retry-delay 2 --retry-connrefused --progress-bar -o "$TARBALL" "https://www.cpan.org/src/5.0/$TARBALL"
CHECKSUM_FILE="${TARBALL}.sha256.txt"
curl -fL --retry 3 --retry-delay 2 --retry-connrefused --progress-bar -o "$CHECKSUM_FILE" "https://www.cpan.org/src/5.0/$CHECKSUM_FILE"
EXPECTED="$(tr -d '\n\r' < "$CHECKSUM_FILE")"
printf '%s  %s\n' "$EXPECTED" "$TARBALL" | sha256sum -c -

SOURCE_DIR="${TARBALL%.tar.gz}"
tar -xzf "$TARBALL"
cd "$SOURCE_DIR"

./Configure -des -Dprefix="$INSTALL_PREFIX"
make
make test
sudo make install | tee "$INSTALL_LOG"

NEW_VERSION=$($INSTALL_PREFIX/bin/perl -v | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)
echo "$(date): Successfully updated to $NEW_VERSION" >> "$LOG_FILE"
echo "Perl successfully updated to $NEW_VERSION"

Save the file, then make it executable:

chmod +x "$HOME/perl-build/update-perl.sh"

Run the Perl Update Script on Debian

Run the script whenever you want to check for a newer stable Perl release:

$HOME/perl-build/update-perl.sh

When nothing new is available, the script exits quickly:

Current version: v5.42.1
Latest version:  v5.42.1
Perl is already up to date.

When a newer build is available, the final lines look like this:

Current version: v5.40.1
Latest version:  v5.42.1
All tests successful.
Perl successfully updated to v5.42.1

Run this script manually instead of from cron. A source rebuild can stop on dependency issues, failed tests, or temporary network problems, and it is much easier to fix those when you are watching the output.

Test Perl on Debian with a Hello World Script

A short script confirms the interpreter, shebang handling, and execute permissions all work the way you expect.

Write a Perl Hello World Script on Debian

Create a small script directly from the shell:

printf '%s\n' '#!/usr/bin/env perl' 'print "Hello, world!\\n";' > hello.pl

The shebang #!/usr/bin/env perl follows your current PATH, so it works with Debian’s packaged Perl and with a source-built Perl under /usr/local/bin.

Make the Perl Script Executable on Debian

Add execute permission to the script:

chmod +x hello.pl

Run the Perl Test Script on Debian

Execute the script from the current directory:

./hello.pl
Hello, world!

Troubleshoot Perl on Debian

These checks cover the two Debian-specific problems readers hit most often: an unexpected Perl binary in PATH, and a minimal install that has /usr/bin/perl but not the full tooling.

Fix an Unexpected Perl Version on Debian

If perl -v shows a different version than you expected after using both methods, inspect every Perl binary your shell can see:

type -a perl
perl is /usr/local/bin/perl
perl is /usr/bin/perl
perl is /bin/perl

The first match is the one your shell runs by default. Use /usr/bin/perl script.pl when you want Debian’s packaged runtime, use /usr/local/bin/perl script.pl when you want the source build, and keep #!/usr/bin/env perl in new scripts when you want them to follow your current PATH.

Verify the active interpreter again after choosing the path you want:

which perl
perl -v | head -2
/usr/local/bin/perl

This is perl 5, version 42, subversion 1 (v5.42.1) built for x86_64-linux

Install the Full Perl Package Instead of perl-base on Debian

If perl -v works but cpan or perldoc is missing, Debian is probably running only the essential runtime:

dpkg -S /usr/bin/perl
perl-base: /usr/bin/perl

If that base interpreter is present but the full perl package is not, commands such as cpan and perldoc stay unavailable until you install the larger package.

Install the full package if you need the missing tools:

sudo apt install perl

Check that both commands are now available:

command -v cpan
command -v perldoc
/usr/bin/cpan
/usr/bin/perldoc

Remove Perl from Debian

APT-installed Perl and a source-built Perl clean up differently. On Debian, removing the perl package does not remove the essential perl-base runtime, so /usr/bin/perl remains available for core system tools.

Remove the Perl Package from Debian

Preview the removal transaction first. On Debian 13, removing perl can also mark packages such as Git, build tools, Apache helpers, and GNOME components for removal when they depend on it.

sudo apt remove -s perl | sed -n '1,20p'
REMOVING:
  apache2-bin
  build-essential
  dpkg-dev
  git
  gnome

Review the simulated removal list carefully before you continue. On many Debian systems, removing the full perl package is not an isolated change.

If the preview only lists packages you are prepared to remove, continue with the actual removal:

sudo apt remove perl
sudo apt autoremove

Refresh APT metadata before checking the installed state:

sudo apt update

Trim the verification output to the installed-state lines so the result is easy to read across Debian 13, 12, and 11:

apt-cache policy perl | sed -n '1,2p'
perl:
  Installed: (none)

This removes the full perl package, but Debian still keeps /usr/bin/perl through perl-base.

Remove the Source-Built Perl on Debian

If you kept $HOME/perl-build/perl-install.log from the source install, reuse that manifest for a safer cleanup instead of hand-maintaining a long removal list.

This deletes the source-built files under /usr/local. If you added CPAN modules to that same prefix, back up /usr/local/lib/perl5 first.

The sed command removes the leading spaces from the install log, and xargs feeds each recorded path back to rm -f:

grep '^  /usr/local/' "$HOME/perl-build/perl-install.log" | sed 's/^  //' | sudo xargs -r rm -f
sudo rm -rf /usr/local/lib/perl5 "$HOME/perl-build"

Confirm that Debian’s packaged Perl is active again:

which perl
perl -v | head -2
/usr/bin/perl

This is perl 5, version 40, subversion 1 (v5.40.1) built for x86_64-linux-gnu-thread-multi

Perl on Debian FAQ

What Perl version does Debian ship?

Debian’s default APT sources currently provide Perl 5.40.1 on Debian 13, 5.36.0 on Debian 12, and 5.32.1 on Debian 11. If you need newer upstream Perl, the source-build method installs Perl 5.42.1 under /usr/local.

Is Perl already installed on Debian?

Many Debian systems already include Perl, and minimal installs usually still keep perl-base because it is essential. If perl -v works but cpan or perldoc is missing, install the full perl package with sudo apt install perl.

Should I use Debian’s Perl package or compile Perl from source on Debian?

Use Debian’s package for most systems because it receives security updates through APT and stays aligned with Debian packages. Compile from source only when you need a newer upstream release or want it isolated under /usr/local.

Can I install Perl modules with APT instead of CPAN on Debian?

Yes. Debian packages many common modules as lib…-perl packages, which makes them easier to update and remove with APT. Use CPAN when the module is missing from Debian or when you need a newer release than the repository provides.

Conclusion

Perl is now installed on Debian with either the distro package or a newer /usr/local source build, so you can start running scripts, parsing logs, and adding modules right away. For DBI-backed projects, install Git on Debian to manage your code and install SQLite on Debian or install MariaDB on Debian for the database layer.

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 coffee Buy 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:

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

Leave a Comment

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

Let us know you are human: