Why can't I install a package onto my Amazon EC2 Linux instance?
I want to install a package on my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance, but the package installation fails.
Resolution
To troubleshoot package installation issues on your EC2 instance, take the following actions.
Check your configuration for issues
Run the following command to check available disk space:
df -h
If the disk space is full or almost full, then reduce the amount of disk space that you use.
Run the following command to open the repository configuration files:
ls -l /etc/yum.repos.d/ cat /etc/yum.repos.d/*.repo
In the files, check for the following issues:
- Syntax errors, missing baseurl or mirrorlist entries, or truncated files that can cause yum or dnf to fail when it resolves packages.
- Incorrect or unreachable URLs, or decommissioned mirrors.
Note: This issue typically occurs in custom or third-party repositories. - Packages that are in deactivated repositories with the Enabled parameter set to 0.
- Multiple repository files that provide the same packages at different versions, and then cause dependency failures.
- Keys with the gpgcheck parameter set to 1 that are missing or have a path that's not valid.
Run the following command to check for locked package manager processes:
ps aux | grep -E 'yum|dnf'
To identify stale lock files, check whether the lock file's persistent identifier (PID) is part of a running process. If the locked process is actively running, then wait for the process to finish.
To remove stale lock files, run the following command:
sudo rm -f /var/cache/dnf/*
Note: For instances that run Amazon Linux 2 (AL2), replace /var/cache/dnf/* with /var/run/yum.pid.
Run the following command to check for network connectivity to repository endpoints:
curl -I https://cdn.amazonlinux.com
If you can't connect, then see How do I troubleshoot connection issues to AWS service endpoints from Amazon EC2 Linux?
Make sure that your instance's security group allows outbound HTTPS traffic on port 443 to the repository. Also, make sure that your instance can connect to the internet. For instances in public subnets, use an internet gateway. For instances in private subnets, use a NAT gateway or NAT instance. Or, to access repositories without internet access, use virtual private cloud (VPC) endpoints for Amazon Simple Storage Service (Amazon S3).
Run the following command to check system logs for additional error details:
sudo tail -f /var/log/messages sudo journalctl -xe
Run the following command to verify that Security-Enhanced Linux (SELinux) doesn't block package operations:
getenforce sudo ausearch -m avc -ts recent
If the output contains Enforcing and the audit log shows blocks from SELinux, then check your SELinux configuration.
To check whether your system can access the repository, run the following command:
sudo dnf repolist sudo dnf check-update
Note: For AL2, replace dnf with yum.
If the repository is unreachable, then you receive errors in the command output. Take troubleshooting actions based on the error that you receive.
Run the following command based on your package manager tool to check for misconfigured dependencies, conflicting version requirements, or references to removed packages.
yum:
yum deplist
dnf:
dnf repoquery --requires
pip:
pip show displays dependencies
Check your OS and version for compatibility issues
If you install packages on an end-of-life operating system (OS), then installation fails because the OS repositories don't provide updated packages or later versions of dependencies. As a result, you receive an error message that's similar to the following example:
"Error: Package: s3fs-fuse-1.94-1.el7.x86_64 (epel) Requires: fuse >= 2.8.4 Available: fuse-2.8.3-5.el6.x86_64 (rhel-6-server-rpms) fuse = 2.8.3-5.el6 Error: Package: s3fs-fuse-1.94-1.el7.x86_64 (epel)
Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit) Error: Package: s3fs-fuse-1.94-1.el7.x86_64 (epel) Requires: libc.so.6(GLIBC_2.17)(64bit)"
In the error message, the text that uses the .el# format in the package name refers to the version. For example, s3fs-fuse-1.94-1.el7.x86_64 (epel) refers to a package for Red Hat Enterprise Linux (RHEL) or CentOS 7.
To resolve this issue, complete the following steps to migrate to a supported OS version:
- Launch a new instance that uses the latest available Amazon Machine Image (AMI) for your Linux distribution.
- Transfer your files, databases, and applications from the original instance to the new instance.
- Install the required packages onto the new instance.
- Test your applications on the new instance to make sure that they work as expected.
- Update your DNS records, load balancers, or other routing configurations to point to the new instance.
- Terminate the original instance.
Important: For more information about supported OS versions for your Linux distribution, see the following resources:
- For RHEL, see Red Hat Enterprise Linux life cycle on the Red Hat website.
- For Amazon Linux, see Upgrade from Amazon Linux 2 to Amazon Linux 2023.
- For Ubuntu, see List of releases on the Ubuntu website.
Make sure that your application uses the correct version of the core system libraries
If your application requires a later version of a core system library such as glibc, then you receive "Version not found" error messages when you run the application. It's a best practice to migrate to a later OS version that includes the required library version. It's not a best practice to manually update the library as manual updates can cause system issues.
For example, for AL2 instances that require glibc 2.29 or later, migrate to Amazon Linux 2023 (AL2023).
Note: AL2 will reach end of life on June 30, 2026. Migrate all AL2 instances to AL2023 before the end-of-support date. For information about differences between the versions, see Comparing AL2 and AL2023.
Check whether the package is available in the standard repository
If the required package version isn't available through standard package management, then you receive dependency error messages similar to "Package not found".
To resolve this issue, use a version that's available in the standard repository. Or, see How do I install a package that's not available in the repository onto my Amazon EC2 Linux instance?
Check whether the package manager is missing or broken
If the package manager is missing or broken, then package installation fails. As a result, you receive error messages that the system couldn't find the package manager binary.
Example error messages:
"bash: yum command not found"
"apt-get: No such file or directory"
To troubleshoot this issue, see How do I troubleshoot a missing or broken package manager in my Amazon EC2 Linux instance?
Check for package conflicts
If your system has residual packages or dependencies, then you might encounter package installation issues because security scanning tools can detect earlier versions of packages even after upgrades. The residual packages might have earlier library versions that conflict with later installations.
To resolve this issue, complete the following steps to identify and remove the residual packages:
- Run the following command based on your distribution to list all installed packages.
RHEL:
Note: Replace example-package with the package name and example-library with the library name.rpm -qa | grep -i example-package rpm -qa | grep -i example-library
Debian:
Note: Replace example-package with the package name and example-library with the library name.dpkg -l | grep -i example-package dpkg -l | grep -i example-library
Check the output for Open Database Connectivity (ODBC) packages, client libraries, or dependencies that have earlier versions than the package that you want to install. For example, check the postgresql-odbc ODBC driver for Python bindings such as python3-psycopg2, or look for earlier library versions such as libpq. - Run the following command based on your distribution to remove the identified packages and libraries:
RHEL:
Note: Replace example-package with the package name and example-library with the library name. For AL2, replace dnf with yum.sudo dnf remove example-package example-library
Debian:
Note: Replace example-package with the package name and example-library with the library namesudo apt remove example-package example-library - Run the following command to confirm that you removed the library:
Note: Replace example-library with the library name.rpm -qa | grep -i example-library
If the command output is empty, then there are no earlier versions of the library. - Run the following command based on your distribution to confirm that you removed the earlier versions of the packages.
RHEL:
Note: Replace example-package with your package name.rpm -qa | grep -i example-package - Debian:
Note: Replace example-package with your package name.dpkg -l | grep -i example-package
Note: It's a best practice to use Amazon Inspector to scan packages on your instances. For information about costs, see Amazon Inspector pricing.
Make sure that you meet the package's version compatibility requirements
Some tools enforce version compatibility requirements to make sure that they work as expected. For example, pg_dump requires the client version to be the same major version or higher than the PostgreSQL database server version.
If you don't meet the package version requirements, then you receive an error message that's similar to the following example:
"pg_dump: server version: 14.6; pg_dump version: 12.3
pg_dump: aborting because of server version mismatch"
Use the error message to identify the required version. Then, install the minimum required version or later of the client tool.
If you have multiple versions installed, then run the following command to identify the path to the correct version:
/usr/pgsql-17/bin/pg_dump -h endpoint -U username -d database_name > backup.sql
Note: Replace endpoint with your endpoint, username with your username, database_name with your database name.
Troubleshoot npm package installation failures
Prerequisites:
-
Create an AMI to use as a backup in case you encounter issues. To avoid downtime, clear Reboot instance when you create the AMI.
-
Run the following command to verify that your instance can connect to the internet:
ping -c 4 8.8.8.8 -
Run the following command to test connectivity to the package registry:
curl -I https://registry.npmjs.orgNote: If your instance has connectivity issues, then troubleshoot internet connection issues.
Typically, npm package installation fails because of network connectivity or API response parsing issues. To troubleshoot, check the npm debug log that's listed in the error message for more information.
If the issue is with a specific package version, then run the following command to install a different version that meets your dependency requirements.
npm install @packagename#.#.#
Note: Replace @packagename with the package name and #.#.# with the package version number.
As a temporary workaround, remove the dependency with issues from package-lock.json so that you can install the package. If the installation succeeds, then check whether you need to include the dependency in your application.
If you still encounter issues, then make sure that your Node.js version meets the package's engine requirements. Also, make sure that you installed any required build tools and check the package's GitHub repository for version-specific issues and workarounds.
Prevent package installation issues
Use the following best practices to minimize package installation failures on your Linux instances:
- Test updates in non-production environments before you apply them to production instances.
- Regularly monitor available disk space to prevent installation failures that occur because of insufficient storage.
- Use the latest AMIs to launch new instances so that you start with up-to-date package repositories and system components.
- Regularly update your packages.
- Don't mix package managers. For example, don't install Python packages with both pip and yum for the same package.
- Check Amazon Linux Security Advisories to stay informed about security vulnerabilities and required updates.
- Note custom repository configurations or package installations in case you need to troubleshoot issues.
- Use Patch Manager, a capability of AWS Systems Manager, to automatically scan and install patches on your instances.
- Use virtual environments, such as venv or virtualenv for Python, to isolate package dependencies and prevent system-wide conflicts.
- Topics
- Compute
- Tags
- Amazon Linux
- Language
- English

Relevant content
- Accepted Answer
asked 2 years ago
- Accepted Answer
asked 2 years ago
- Accepted Answer
asked 3 years ago
asked 2 years ago