Perl modules vanish after an Ubuntu upgrade: escaping the version-locked @INC trap

Abstract: Ubuntu release upgrades change the Perl version, which orphans modules installed from CPAN under version-specific directories. Installing modules from apt instead keeps them working across upgrades.

Created: 2026-11-02 by

The module isn't gone — it's just invisible. Ubuntu's Perl upgrades (5.34 on 22.04, 5.38 on 24.04, 5.40 after that) each search a different set of version-numbered directories listed in @INC, so anything you installed from CPAN under the old version's directory is never looked at again. The lasting fix is to install Perl modules from Ubuntu's own packages — here, sudo apt install libdatetime-format-strptime-perl — because apt keeps its modules matched to the installed interpreter across release upgrades. Treat CPAN as the fallback, not the default.

Why a Perl upgrade hides your modules

The @INC list in the error message belongs to one specific interpreter build. Ubuntu gives every major Perl version its own site directories: under Perl 5.38.2 that includes /usr/local/share/perl/5.38.2, and under 5.40 the equivalent directory carries the new number. When you install with cpan, the module is placed into the directory of the interpreter you ran it with — and nothing records that it should follow you to the next one.

That's why the old file still exists on disk yet the upgraded interpreter can't find it: no entry in the new @INC points there, and neither apt nor CPAN tooling migrates it. Modules from Ubuntu packages behave differently. Pure-Perl parts land in /usr/share/perl5, which is not version-numbered, while compiled parts go under a versioned architecture directory; each package declares the Perl API it requires, so a release upgrade automatically pulls in builds made for the new interpreter.

Confirm the diagnosis

Two quick checks make the picture unambiguous:

perl -V
find /usr/local/share/perl /usr/local/lib/perl -name 'Strptime.pm'

The first shows the running Perl version and the full search path; the second locates copies of the module on disk. If the file turns up only under an old version directory while perl -V reports a newer one, this is exactly the failure mode — the interpreter's search list and your installed files have drifted apart.

The durable fix: let apt manage your modules

Most popular CPAN distributions are packaged for Ubuntu. The naming convention is predictable: DateTime::Format::Strptime becomes libdatetime-format-strptime-perl — a lib prefix, lowercase with :: replaced by dashes, and -perl appended. To find packages for other modules:

sudo apt install apt-file && sudo apt-file update
apt-file search Strptime.pm
apt-cache search --names-only 'libdatetime-format-strptime'

Then install, enabling the universe repository first if it isn't active:

sudo add-apt-repository universe
sudo apt install libdatetime-format-strptime-perl

Because dpkg now owns the module, dependencies are resolved automatically, security updates arrive through the normal package channels, and the next release upgrade carries the module forward with the interpreter instead of stranding it.

When a module only exists on CPAN

Sometimes you genuinely need something the repositories lack. In that case, avoid scattering installs into version-locked directories. Install cpanminus from apt and give it a stable, version-independent home:

sudo apt install cpanminus
cpanm --local-lib /opt/perl-local DateTime::Format::Strptime

Add the resulting library path to ~/.profile:

export PERL5LIB="/opt/perl-local/lib/perl5${PERL5LIB:+:$PERL5LIB}"

This path contains no version number, so it stays on the search path across upgrades. One caveat: modules with compiled C components are built for a specific interpreter, so after a major Perl upgrade they must be rebuilt even though the directory is unchanged. Keep a cpanfile listing what you depend on so the rebuild is one scripted command:

# cpanfile
requires 'DateTime::Format::Strptime';
# after an interpreter upgrade:
cpanm --local-lib /opt/perl-local --installdeps .

As a one-off stopgap, PERL5LIB=/usr/local/share/perl/5.34.0 perl script.pl can unblock a broken script immediately — but only for pure-Perl code. Binary extensions compiled for the old interpreter can crash the new one, so don't make a habit of it.

Habits that prevent a repeat

  • Default to apt for Perl modules; reach for CPAN only when a module is missing from the repositories or you need a feature from a newer version.
  • After any release upgrade, run ls /usr/local/share/perl/ — more than one version directory means CPAN-installed modules were stranded and need reinstalling.
  • Keep a manifest (cpanfile or a plain list) of every CPAN module you rely on, so recovery is scripted rather than improvised.
  • For scripts you deploy elsewhere, vendor dependencies next to the script with cpanm -L local ... so they travel with the code, not the OS.

Frequently Asked Questions

Why can't Perl just keep searching the old directories?

Version separation is deliberate: binary modules are compiled against one interpreter and can misbehave under another. Keeping each build's site libraries separate prevents an upgrade from silently mixing incompatible code.

Is symlinking the old version directory to the new one safe?

It often works for pure-Perl modules, but any compiled extension in that tree was built for the previous interpreter and can crash the current one. Reinstalling — or better, installing the apt package — is the reliable route.

How do I tell which modules came from apt and which from CPAN?

Anything under /usr/local was installed outside the package manager. For a specific file, run dpkg -S /path/to/Module.pm: if dpkg owns it, upgrades will maintain it; if not, it's yours to track.

The cpan command printed thousands of lines. Is that normal?

Yes. CPAN builds each module and its dependency chain from source, which is slow and noisy. The matching apt package installs prebuilt binaries with dependencies resolved in seconds.

What should I do right now if a script is broken?

Check for an apt package for the missing module and install it — that's the permanent fix. If none exists, reinstall via cpanm into a stable local directory, or temporarily set PERL5LIB to the old version directory as a stopgap.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More