How to Install Perl on Debian 13, 12 and 11

Install Perl on Debian 13, 12, and 11 with APT or source. Covers default versions, module packages, update scripts, and removal.

Last updatedAuthorJoshua JamesRead time8 minGuide typeDebian

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 on 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 (Trixie), 5.36.0 on Debian 12 (Bookworm), and 5.32.1 on Debian 11 (Bullseye). Perl.org currently lists 5.42.2 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.

MethodChannelBranchUpdatesBest For
APT packageDebian package indexDebian 13: 5.40.1; Debian 12: 5.36.0; Debian 11: 5.32.1Through APTMost servers and workstations
Source buildPerl.org source downloadsLatest stable sourceManual rebuild with helperNewer 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 | sed -n '2p'
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 | sed -n '2p'
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.
  • libdbi-perl provides the DBI interface used by many database scripts.
  • libdbd-mysql-perl adds the DBI driver 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. Prefer Debian packages when they exist because APT owns their updates and removal. Use CPAN when Debian does not package the module or when your project needs a newer module release. The grep command guide covers the filtering syntax if you want more examples.

apt-cache search perl | grep -E '^lib.*mysql.*-perl'

On Debian 13, relevant output includes:

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

Older releases can expose a shorter list. If a script fails with Can't locate DBI.pm in @INC, install libdbi-perl. Add libdbd-mysql-perl when the script needs the MySQL or MariaDB DBI driver:

sudo apt install libdbi-perl libdbd-mysql-perl

Compile Perl from Source on Debian

Compile Perl from source when you need Perl 5.42.2 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' | sed -n '1p')"
if [ -n "$TARBALL" ]; then
    curl -fLO --progress-bar "https://www.cpan.org/src/5.0/$TARBALL"
    printf 'Tarball: %s\n' "$TARBALL"
else
    printf 'Could not determine the latest Perl tarball from perl.org.\n' >&2
fi

This pipeline uses the curl command guide to read Perl.org and grep -E to isolate the current tarball name. The -fsSL options fail on HTTP errors, keep normal output quiet, show errors when they occur, and follow redirects. Keep using the same terminal session because the checksum and extraction steps reuse the $TARBALL variable.

Tarball: perl-5.42.2.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 this snippet 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.2.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. The gz and tgz extraction guide explains the tar -xzf pattern in more detail.

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

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.

The elapsed time and detailed test counts vary with CPU speed, but the success line should still read All tests successful.

Install the Source-Built Perl on Debian

Record the current /usr/local file list, install the compiled tree, then save a manifest of new files and symlinks that the install added. The Bash wrapper keeps the pipeline exit status tied to make install, not only to tee:

find /usr/local -xdev \( -type f -o -type l \) -print 2>/dev/null | sort > "$HOME/perl-build/usr-local-before.txt"
bash -o pipefail -c 'sudo make install 2>&1 | tee "$HOME/perl-build/perl-install.log"'
find /usr/local -xdev \( -type f -o -type l \) -print 2>/dev/null | sort > "$HOME/perl-build/usr-local-after.txt"
comm -13 "$HOME/perl-build/usr-local-before.txt" "$HOME/perl-build/usr-local-after.txt" > "$HOME/perl-build/perl-install-manifest.txt"

The tee command writes a copy of the install output to $HOME/perl-build/perl-install.log while still printing it on screen. The comm command compares the before-and-after file lists and saves the new /usr/local paths to $HOME/perl-build/perl-install-manifest.txt for cleanup.

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 | sed -n '2p'
/usr/local/bin/perl
This is perl 5, version 42, subversion 2 (v5.42.2) 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

Install the update helper as a short user command while keeping its build workspace under $HOME/perl-build. The setup block refreshes PATH for the current terminal; Debian’s default .profile normally adds $HOME/.local/bin for new login sessions when that directory exists. The chmod command guide covers permission changes if you want more background on the execute bit.

mkdir -p "$HOME/.local/bin" "$HOME/perl-build"
case ":$PATH:" in
    *":$HOME/.local/bin:"*) ;;
    *) export PATH="$HOME/.local/bin:$PATH" ;;
esac

cat > "$HOME/.local/bin/update-perl" <<'EOF'
#!/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"
MANIFEST="$BUILD_DIR/perl-install-manifest.txt"

for cmd in curl gcc make sha256sum sudo tar; 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]+' | sed -n '1p' || echo "none")
DOWNLOAD_PAGE=$(curl -fsSL https://www.perl.org/get.html)
TARBALL=$(printf '%s\n' "$DOWNLOAD_PAGE" | grep -oE 'perl-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' | sed -n '1p' || true)

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
find "$INSTALL_PREFIX" -xdev \( -type f -o -type l \) -print 2>/dev/null | sort > "$BUILD_DIR/usr-local-before.txt"
sudo make install 2>&1 | tee "$INSTALL_LOG"
find "$INSTALL_PREFIX" -xdev \( -type f -o -type l \) -print 2>/dev/null | sort > "$BUILD_DIR/usr-local-after.txt"
comm -13 "$BUILD_DIR/usr-local-before.txt" "$BUILD_DIR/usr-local-after.txt" > "$BUILD_DIR/perl-install-manifest.new"
if [ -f "$MANIFEST" ]; then
    sort -u "$MANIFEST" "$BUILD_DIR/perl-install-manifest.new" > "$BUILD_DIR/perl-install-manifest.merged"
    mv "$BUILD_DIR/perl-install-manifest.merged" "$MANIFEST"
else
    mv "$BUILD_DIR/perl-install-manifest.new" "$MANIFEST"
fi

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

chmod +x "$HOME/.local/bin/update-perl"
command -v update-perl | sed "s|$HOME|~|"
~/.local/bin/update-perl

The helper clears old perl-* source directories and tarballs inside $HOME/perl-build before rebuilding, but it does not remove the currently installed Perl until the new build passes its test suite. The cleanup uses find -exec only inside that build workspace.

Run the Perl Update Script on Debian

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

update-perl

When nothing new is available, the script exits quickly:

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

When a newer build is available, the helper downloads the current tarball, verifies its checksum, runs Configure, builds Perl, runs make test, and installs only after the test suite succeeds.

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 | sed -n '2p'
/usr/local/bin/perl
This is perl 5, version 42, subversion 2 (v5.42.2) 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-get -s remove perl | sed -n '/^The following packages will be REMOVED:/,/^[0-9]/p' | sed -n '1,12p'
The following packages will be REMOVED:
  autoconf automake bsd-mailx build-essential debhelper dh-autoreconf
  dh-strip-nondeterminism dkms docbook-xml dpkg-dev exim4-base
  exim4-daemon-light git gnome-software gnome-software-plugin-deb
  gnome-software-plugin-fwupd intltool-debian libalgorithm-diff-perl

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 package removal:

sudo apt remove perl

After the package removal, let APT show any dependencies that are no longer required before you decide whether to remove them:

sudo apt autoremove

Confirm that the full perl package is no longer installed:

if dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' perl 2>/dev/null | grep -q '^ii'; then
    echo "perl package is still installed"
else
    echo "perl package is not installed"
fi
perl package is not installed

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-manifest.txt 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.

Preview the manifest first, then remove those files only if the paths belong to the source-built Perl you installed:

sed -n '1,20p' "$HOME/perl-build/perl-install-manifest.txt"
printf '%s\n' /usr/local/lib/perl5 "$HOME/.local/bin/update-perl" "$HOME/perl-build"

The xargs -r command feeds each manifest path back to rm -f only when the list is not empty. The cleanup changes back to your home directory before deleting the build workspace, so the shell does not remain inside a removed directory.

cd "$HOME"
sudo xargs -r rm -f < "$HOME/perl-build/perl-install-manifest.txt"
sudo rm -rf /usr/local/lib/perl5
rm -f "$HOME/.local/bin/update-perl"
rm -rf "$HOME/perl-build"
hash -r

Confirm that Debian’s packaged Perl is active again:

which perl
perl -v | sed -n '2p'
/usr/bin/perl
This is perl 5, version 40, subversion 1 (v5.40.1) built for x86_64-linux-gnu-thread-multi

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.

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.

Verify before posting: