This relocation error occurs when your apt package manager has library version mismatches, typically caused by mixing packages from different distributions or incomplete upgrades. The fix involves reinstalling apt and libapt-pkg packages to restore compatibility.
The relocation error happens when the apt binary cannot find or properly load the libapt-pkg library it depends on. This indicates a symbol version mismatch—the apt executable was built against a different version of libapt-pkg than what's currently installed on your system. This commonly occurs after: - A partial or interrupted system upgrade - Mixing packages from different Ubuntu/Debian versions (e.g., Focal and Jammy) - Installing third-party PPAs that provide incompatible package versions - Manual package manipulation or downgrades that left the system inconsistent The error appears because GCC changed symbol mangling in version 7+, and when apt and libapt-pkg versions don't match, the binary cannot find the expected library symbols at runtime.
First, check which repositories are enabled and look for anything from non-standard sources:
cat /etc/apt/sources.list
ls -la /etc/apt/sources.list.d/Look for any PPAs or third-party repositories that might provide their own apt packages. If you find suspicious entries, disable them:
# Comment out problematic lines in /etc/apt/sources.list
sudo nano /etc/apt/sources.list
# Or remove third-party repo files
sudo rm /etc/apt/sources.list.d/problematic-repo.listOnly keep the official Ubuntu or Debian repositories for your release.
Attempt to repair broken packages using dpkg. This can work even when apt is broken:
sudo dpkg --configure -aThis tells dpkg to complete any partial installations. If this succeeds, try:
sudo apt --fix-broken installIf apt still doesn't work, proceed to the next step.
If dpkg alone doesn't fix it, manually reinstall the apt packages. First, try to download the package files from the Ubuntu/Debian mirror:
For Ubuntu/Debian online systems:
# Try to download and install directly
sudo apt-get install --reinstall apt libapt-pkg6.0If that fails (because apt doesn't work), use dpkg directly:
# Check your system's release
lsb_release -csThen download the matching packages from https://packages.ubuntu.com or https://packages.debian.org and install with dpkg:
# Example for Ubuntu 22.04 (jammy)
cd /tmp
wget http://security.ubuntu.com/ubuntu/pool/main/a/apt/apt_2.4.14_amd64.deb
wget http://security.ubuntu.com/ubuntu/pool/main/a/apt/libapt-pkg6.0_2.4.14_amd64.deb
# Install using dpkg
sudo dpkg -i ./apt_2.4.14_amd64.deb ./libapt-pkg6.0_2.4.14_amd64.debReplace the version numbers and URLs with those appropriate for your distribution release.
If dpkg reports conflicts during installation, use the auto-deconfigure flag:
sudo dpkg -i --auto-deconfigure apt_*.deb libapt-pkg6.0_*.debThis tells dpkg to automatically deconfigure conflicting packages first, then install the new versions. This can help resolve dependency entanglement.
If your system was corrupted by a problematic PPA, prevent it from causing issues again:
# If the PPA package is still installed
sudo apt-get remove ppa-purge
sudo ppa-purge ppa:problematic/repo
# Or manually remove the repo
sudo rm /etc/apt/sources.list.d/problematic-repo.list
# Clean APT cache
sudo apt-get clean
sudo apt-get autocleanAfter cleaning, verify your sources list contains only official repositories:
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/Then try apt again:
sudo apt-get updateOnce apt is working again, bring your system fully up to date:
sudo apt-get update
sudo apt-get upgradeIf you want a more aggressive upgrade (useful after fixing from a corrupted state):
sudo apt-get dist-upgradeThis ensures all packages are at compatible versions. After the upgrade, verify everything works:
apt --version
apt-cache search test
sudo apt-get install --dry-run vim # Test without installingIf none of the above works and your system is unbootable, use a live USB:
1. Download Ubuntu or Debian live ISO matching your original release
2. Boot from USB: insert USB and restart, then select boot from USB
3. Once in the live environment, open a terminal
4. Mount your root filesystem:
sudo mount /dev/sdXX /mnt # Replace sdXX with your root partition
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /dev /mnt/dev5. Chroot into your system:
sudo chroot /mnt /bin/bash6. Once inside, repeat steps 1-5 from this guide:
dpkg --configure -a
apt --fix-broken install
apt-get install --reinstall apt libapt-pkg6.07. Exit chroot and reboot:
exit
sudo rebootThis approach works when your main system cannot boot due to apt corruption.
Understanding symbol versioning in Linux:
When a C++ library is built, symbols are created with version information (SONAME). The apt binary is linked against a specific SONAME version (e.g., APTPKG_6.0). If the installed libapt-pkg.so.6.0 was built with a different compiler or from a different source, it may not have the expected symbols, causing the relocation error.
GCC ABI breaking changes:
GCC 7 changed the C++ ABI, which broke compatibility between libraries compiled with GCC 6 and GCC 7+. This is one common cause of symbol version mismatches when mixing packages from different distributions.
Why mixing distributions breaks apt:
Each Debian/Ubuntu release pins specific versions of apt and libapt-pkg to work together. When you mix sources.list entries from Jammy and Focal (for example), you might get a newer apt with an older libapt-pkg, causing exactly this error. APT itself is designed to manage package versions, but it cannot reconcile itself if it's already broken.
Safe recovery without network access:
If your system has no internet access, you can:
1. Copy package files (.deb) from a working machine with the same OS version
2. Use 'apt-offline' tool on a working system to download dependencies
3. Create a local repository on USB and install from it
Prevention:
- Stick to ONE Ubuntu/Debian release per system
- Use official repositories only, or vet PPAs carefully
- Never mix sources.list entries from different releases
- Regularly run apt-get update && apt-get upgrade to keep packages consistent
- Avoid manual package downgrading
Checking library compatibility:
After recovering apt, verify your libraries are consistent:
ldd /usr/bin/apt
ldd /usr/lib/x86_64-linux-gnu/libapt-pkg.so.6.0All dependencies should resolve to libraries from the same release.
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Sub-process /usr/bin/dpkg returned an error code (2)
How to fix "Sub-process /usr/bin/dpkg returned an error code (2)" in APT
dpkg-divert: error: rename involves overwriting 'path' with different file
How to fix dpkg-divert rename conflicts in APT
E: Sub-process /usr/bin/dpkg returned an error code (1) during kernel installation
How to fix "dpkg returned an error code (1)" in APT kernel installation
dpkg: dependency problems prevent configuration of triggers
dpkg: dependency problems prevent configuration of triggers in apt