How to Install Perl on Ubuntu 26.04, 24.04 and 22.04

Last updated Wednesday, April 29, 2026 4:10 pm Joshua James 8 min read

Perl still solves the jobs that turn shell pipelines into unreadable knots, especially when you are cleaning logs, reshaping text, or keeping older admin scripts alive. Most people who need to install Perl on Ubuntu only need the package from Ubuntu’s repositories, while a separate source build makes sense when you want the newest upstream branch under /usr/local.

On Ubuntu, the package name is simply perl, while many add-on modules follow the lib...-perl naming pattern. For the supported LTS releases covered here, Ubuntu 26.04 (Resolute) ships Perl 5.40.1, Ubuntu 24.04 (Noble) ships 5.38.2, and Ubuntu 22.04 (Jammy) ships 5.34.0. Use APT for the normal download and install path before you reach for CPAN or a source build.

Install Perl on Ubuntu

APT is the safer default because it keeps Perl aligned with Ubuntu packages and security updates. Perl.org currently lists Perl 5.42.2 as the latest stable source release, so build from source only when the packaged branch is too old for your project or you deliberately want a separate runtime outside Ubuntu’s package database.

MethodChannelVersionUpdatesBest For
APT packageUbuntu package indexDistribution defaultAutomatic via APTMost servers, workstations, and admin scripts
Source buildPerl.org source downloadsLatest stableManual rebuildNewer upstream Perl or a separate /usr/local runtime

The current Ubuntu package revisions and shared-library package names are:

Ubuntu ReleaseAPT Package RevisionShared Library Package
Ubuntu 26.04 (Resolute)5.40.1-7build1libperl5.40
Ubuntu 24.04 (Noble)5.38.2-3.2ubuntu0.2libperl5.38t64
Ubuntu 22.04 (Jammy)5.34.0-3ubuntu1.5libperl5.34

Those package revisions matter when a native module, embedded interpreter, or older application asks for a specific Perl ABI. For normal scripts, the shorter upstream version such as v5.40.1 is usually enough.

Install Perl from Ubuntu APT Packages

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

Check the Existing Perl Installation on Ubuntu

Check whether Ubuntu 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 already works but cpan or perldoc is missing, Ubuntu is probably giving you the essential perl-base runtime rather than the full perl package.

Update the Ubuntu 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 new user to sudoers on Ubuntu.

Install the Perl Package on Ubuntu

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

sudo apt install perl

Check the installed package state after APT finishes:

apt-cache policy perl | sed -n '1,7p'
perl:
  Installed: 5.40.1-7build1
  Candidate: 5.40.1-7build1
  Version table:
 *** 5.40.1-7build1 500
        500 http://au.archive.ubuntu.com/ubuntu resolute/main amd64 Packages
        100 /var/lib/dpkg/status

On Ubuntu 24.04 the same check reports 5.38.2-3.2ubuntu0.2, and on Ubuntu 22.04 it reports 5.34.0-3ubuntu1.5. If perl -v already worked before this step, the main difference now is that the full package adds tools such as cpan and perldoc.

Install Common Perl Modules on Ubuntu

Ubuntu 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

APT-installed modules extend Ubuntu’s packaged Perl under /usr/bin/perl. If you later compile Perl under /usr/local, install modules for that runtime with /usr/local/bin/cpan so the two module trees do not get mixed together.

Find Additional Perl Modules on Ubuntu

Ubuntu names most repository modules with the lib...-perl pattern, so a targeted package search is usually faster than scanning the full package list.

apt-cache search '^lib.*mysql.*perl'
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 Ubuntu

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

Install Perl Build Dependencies on Ubuntu

Install the compiler toolchain and the libraries Perl detects during configuration. If you want more detail on the compiler side, see install GCC on Ubuntu.

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 Ubuntu

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 Ubuntu

Download the current stable tarball directly from Perl.org without hardcoding the version number. The curl command guide and grep command guide explain the pieces if you want more detail.

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
curl -fLO --progress-bar "https://www.cpan.org/src/5.0/$TARBALL"
printf 'Tarball: %s\n' "$TARBALL"
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. Keep using the same terminal session because the checksum and extraction steps reuse the $TARBALL variable.

Verify the Perl Tarball Checksum on Ubuntu

CPAN publishes a separate SHA256 file for the Perl tarball. That sidecar file contains only the hash value, so the next command reformats it for sha256sum -c.

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 Ubuntu

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

Configure the Perl Build on Ubuntu

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

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

Relevant output includes:

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 Ubuntu

Compile the source tree before you run the test suite:

make

Relevant output includes:

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

Run the Perl Test Suite on Ubuntu

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

make test

Relevant output includes:

All tests successful.

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

Install the Source-Built Perl on Ubuntu

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 Ubuntu

Check which Perl binary your shell now prefers and confirm the upstream version:

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

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

Standard Ubuntu interactive shells already place /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 Ubuntu’s packaged Perl tree.

Update Source-Built Perl on Ubuntu

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 Ubuntu

Write the updater into the same build workspace so it can reuse your logs and source tree without leaving you in a text editor.

cat > "$HOME/perl-build/update-perl.sh" <<'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"

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"
EOF

Put the updater on your PATH so you can run it as update-perl from any shell. The install -m 0755 command copies the file to /usr/local/bin and makes it executable in one step.

sudo install -m 0755 "$HOME/perl-build/update-perl.sh" /usr/local/bin/update-perl

Check that your shell can find the updater command before you use it:

command -v update-perl
/usr/local/bin/update-perl

Run the Perl Update Command on Ubuntu

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

update-perl

When nothing new is available, the updater 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 final lines look like this:

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

Run this updater 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 Ubuntu 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 Ubuntu

Create a small script directly from the shell:

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

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

Make the Perl Script Executable on Ubuntu

Add execute permission to the script. The +x mode tells the shell that this file can be run as a program.

chmod +x hello.pl

Run the Perl Test Script on Ubuntu

Execute the script from the current directory:

./hello.pl
Hello, world!

Troubleshoot Perl on Ubuntu

These checks cover the Ubuntu-specific problems readers hit most often: missing modules, an unexpected Perl binary in PATH, and systems that only kept perl-base.

Fix Missing Perl Modules on Ubuntu

If a script reports that it cannot locate a module, start with the package name shown in the error and search Ubuntu’s repositories for the matching lib...-perl package.

Can't locate DateTime.pm in @INC (you may need to install the DateTime module)
apt-cache search '^libdatetime-perl$'
libdatetime-perl - module for manipulating dates, times and timestamps

Install the matching module package, then rerun your script:

sudo apt install libdatetime-perl

Find libperl.so on Ubuntu

If a native extension or older application asks for libperl.so, first check which release-matched package owns the shared library on your system:

dpkg -S /usr/lib/*/libperl.so*
libperl5.40:amd64: /usr/lib/x86_64-linux-gnu/libperl.so.5.40
libperl5.40:amd64: /usr/lib/x86_64-linux-gnu/libperl.so.5.40.1

Ubuntu 24.04 reports libperl5.38t64, and Ubuntu 22.04 reports libperl5.34. The t64 suffix on Ubuntu 24.04 is normal package naming, not a separate Perl branch.

Supported Ubuntu LTS releases do not provide libperl5.26. If an old binary asks for that ABI, rebuild it against the release’s current Perl package or isolate the old application instead of forcing an obsolete library package onto the system.

Fix an Unexpected Perl Version on Ubuntu

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 Ubuntu’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:

command -v perl
perl -v | head -2
/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 Ubuntu

If perl -v works but cpan or perldoc is missing, Ubuntu 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 Ubuntu

APT-installed Perl and a source-built Perl clean up differently. On Ubuntu, 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 Ubuntu

Preview the removal transaction first. Ubuntu 26.04 uses the newer APT 3 summary format, while Ubuntu 24.04 and 22.04 still show the older The following packages will be REMOVED: wording.

sudo apt remove -s perl

Relevant output can include high-impact packages such as:

REMOVING:
  build-essential
  libgtk3-perl
  perl
  ubuntu-desktop-minimal

Review the simulated removal list carefully before you continue. On development-heavy Ubuntu systems, removing the full perl package may also remove packages that depend on it.

If the preview only lists packages you are prepared to remove, remove the full package:

sudo apt remove perl

If APT reports unused dependencies afterward, preview the automatic cleanup before running it:

sudo apt autoremove -s

Run the cleanup only when the simulated list contains packages you are comfortable removing:

sudo apt autoremove

Verify that the full package no longer has an installed ii state:

dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' perl | grep '^ii' || echo "perl package is not installed"
perl package is not installed

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

Remove the Source-Built Perl on Ubuntu

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.

Remove the update-perl helper too so the PATH command does not survive after the source-built runtime is gone.

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 -f /usr/local/bin/update-perl
sudo rm -rf /usr/local/lib/perl5 "$HOME/perl-build"
hash -r

Confirm that Ubuntu’s packaged Perl is active again:

command -v 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

Conclusion

Perl is ready on Ubuntu with either the distro package or a newer source build under /usr/local, so you can start running scripts, parsing logs, and adding modules right away. For project work around that runtime, install Git on Ubuntu to track your scripts. If those scripts need a local datastore, install SQLite on Ubuntu or install MariaDB on Ubuntu.

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: