Skip to content

How do I troubleshoot a missing or broken package manager in my Amazon EC2 Linux instance?

8 minute read
0

I want to install a package on my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance. However, installation failed, and I received an error message that the package manager binary wasn't found.

Short description

If the package manager is missing or broken, then you might receive the following error messages when you install a package:

  • "yum: command not found"
  • "apt-get: No such file or directory"
  • "Could not retrieve mirrorlist"
  • "Failed to synchronize cache"
  • "dpkg was interrupted"
  • "rpmdb: Thread/process failed"
  • "Error: rpmdb open failed"
  • HTTP 403 errors

To troubleshoot these errors, repair or restore the broken package manager. If the package manager is missing, then reinstall it.

Note: If the system-release package is missing on Amazon Linux 2023 (AL2023) EC2 instances, then you can't update or install your packages.

Resolution

Note: Amazon Linux 2 (AL2) reached its end of life on June 30, 2026. If you run AL2, then migrate to AL2023 to maintain a supported version. For commands, AL2 uses yum and AL2023 uses dnf.

Repair the broken package manager

For Red Hat Enterprise Linux (RHEL) systems that use yum and dnf, complete the following steps:

  1. Run the following command to clear the package manager cache:

    sudo dnf clean all

    Note: For AL2, replace dnf with yum.

  2. Run the following command to rebuild the package manager database:

    sudo rpm --rebuilddb
  3. Run the following command to confirm that the package manager works as expected:

    sudo dnf check

    Note: For AL2, replace dnf with yum. In the output, check for error messages.

For Debian-based systems that use apt, complete the following steps:

  1. Run the following command to fix broken dependencies:

    sudo apt --fix-broken install
  2. Run the following command to clear the package manager cache:

    sudo apt clean sudo apt autoclean
  3. Run the following commands to update the package lists:

    sudo apt update

If your package manager is still broken, then proceed to the next section.

Reestablish the package manager's dependency chain

Complete the following steps:

  1. Run the following command to check the dnf binary status:

    ls /usr/bin/dnf 
    head -1 /usr/bin/dnf	

    Note: For AL2, replace dnf with yum. In the output, note the path. If you receive the "No such file or directory" error message, then proceed to Reinstall the missing package manager.

  2. Run the following command to identify the Python packages that are still installed:

    rpm -qa | grep python
  3. Run the following command to check the available Python binaries and their expected symbolic links:

    python3 -V 
    ls -l /usr/bin/pyth* 
    ls -l /usr/bin/python
  4. Run the following command to check your PATH environment variable:

    echo $PATH

    Make sure that the /usr/bin/ path is in PATH.

  5. Run the following command to list the contents of /usr/bin to identify the available Python versions:

    ls -al /usr/bin
  6. Run the following command to create a symbolic link from the existing Python installation to the expected location:

    ln -s /usr/bin/python3.9 /usr/bin/python

    Note: Replace python3.9 with your installed Python version.

  7. Run the following command to clean the package manager cache:

    dnf clean all

    Note: For AL2, replace dnf with yum.

  8. Run the following command to confirm that the package manager works as expected:

    dnf --version

    Note: For AL2, replace dnf with yum.

  9. Run the following command make sure that the symbolic link works as expected:

    head -1 /usr/bin/dnf

    Note: For AL2, replace dnf with yum.

  10. Run the following command to confirm that the Python packages are still installed:

    rpm -qa | grep python

If you still encounter broken package manager issues, then you must restore the server from a backup or rebuild the server.

(Only AL2023) Install missing system-release packages

Complete the following steps:

  1. Run the following command to manually configure dnf to use the latest release version:

    echo latest | sudo tee /etc/dnf/vars/releasever
  2. Run the following command to clear the cache to remove corrupted metadata:

    dnf clean all
  3. Run the following command to install the missing system-release package:

    dnf install system-release
  4. Run the following command to confirm that the system-release package is installed:

    rpm -q system-release
  5. Run the following command to test package updates:

    dnf upgrade
    

Reinstall the missing package manager

RHEL-based systems

If dnf or yum is missing but RPM still works, then reinstall the package manager directly from a local RPM file. Complete the following steps:

  1. Run the following command from a working instance with the same operating system (OS) version to download the required RPM packages:

    yumdownloader dnf python3-dnf libdnf
    

    Note: For AL2, replace dnf with yum and python3-dnf with python-urlgrabber.

  2. Transfer the RPM files to the affected instance. Or, run the following command to directly install the package manager:

    sudo rpm -ivh dnf-*.rpm python3-dnf-*.rpm libdnf-*.rpm
    

    Note: If circular dependencies block installation, then run the following commands:

    sudo rpm -ivh --nodeps 
    sudo dnf install dnf 
  3. Run the following command to make sure that your instance has the required package:

    dnf --version

Debian-based systems

If apt or apt-get is missing but dpkg still works, then complete the following steps to reinstall apt from .deb package:

  1. From a working system or from your distribution's package archive, download the apt package and its dependencies. To download the packages, see Ubuntu package searches on the Ubuntu packages website or Packages on the Debian website.

  2. Transfer the .deb files to the affected instance. Or, run the following command to directly install dpkg:

    sudo dpkg -i apt_*.deb libapt-pkg*.deb

    Note: If you receive a dependency error message, then note the missing packages, and then install them from the package archive. Then, reinstall dpkg.

  3. To resolve remaining dependency issues, run the following command:

    sudo apt --fix-broken install
    
  4. Run the following command to make sure that your instance has the required package:

    apt --version

SUSE-based systems

If zypper is missing but RPM is still functional, then complete the following steps to reinstall zypper from the installation media or a downloaded RPM:

  1. Run the following command to get the zypper and libzypp RPM packages from the SUSE installation:
    curl -O https://download.opensuse.org/distribution/leap/15.6/repo/oss/x86_64/zypper-version.x86_64.rpm
    Note: Replace version with the package version for your OS release. The preceding command checks the SUSE repository for SUSE Linux Enterprise Server (SLES) 15.6. For other versions, update the repository download link. For a list of available versions, see Download distribution/leap on the SUSE website.
  2. To find the correct version, run one of the following commands from a working instance that runs the same OS version:
    rpm -qa | grep zypper and rpm -qa | grep libzypp
    -or-
    zypper download zypper libzypp
    Note: Downloaded packages are stored in /var/cache/zypp/packages/.
  3. Transfer the files to the affected instance. Or, run the following command to directly install the package manager:
    sudo rpm -ivh /tmp/zypper-*.rpm /tmp/libzypp-*.rpm
    Note: If circular dependencies block installation, then run the following command to force the installation without dependency checks:
    sudo rpm -ivh --nodeps /tmp/zypper-*.rpm /tmp/libzypp-*.rpm
    sudo zypper install zypper libzypp
    
    Resolve the circular dependencies after you resolve your package manager issues.
  4. Run the following command to make sure that your instance has the required package:
    zypper --version
    Note: If the command returns a version number, then zypper works as expected.

Detach and reattach the Amazon EBS volume to a new instance

If you couldn't reinstall the package manager, then reattach your Amazon Elastic Block Store (Amazon EBS) volume to a new instance. Complete the following steps:

  1. Stop the affected instance.
  2. Detach the root EBS volume from the instance.
  3. Launch a new instance with the same Amazon Machine Image (AMI) as the original instance.
  4. Attach the root volume to the new instance as a secondary volume.
  5. Run the following command to mount the secondary volume and access your data:
    sudo mkdir /mnt/old-root sudo mount /dev/xvdf1 /mnt/old-root
    Note: Replace /dev/xvdf1 with the device name for your attached volume.
  6. Copy data or configurations from the original volume to the new instance.
  7. Run the following command based on your distribution to test the package management tools in the new instance.
    RHEL:
    sudo dnf check
    sudo dnf repolist
    sudo dnf install "package_name" && sudo dnf remove "package_name"
    Note: Replace package_name with your package name.
    Debian:
    sudo apt update
    sudo apt list --upgradable
    sudo apt install -y package_name && sudo apt remove -y package_name
    Note: Replace package_name with your package name.
  8. Terminate the original instance, and then delete its root volume.

Related information

How do I install a package that's not available in the repository on my Amazon EC2 Linux instance?

Why can't I install a package onto my Amazon EC2 Linux instance?

AWS OFFICIALUpdated 17 days ago