Managing packages is a crucial aspect of system administration and development in Linux environments, such as CentOS. This guide is designed to introduce you to the top 20 most common examples of package manager usage on CentOS. Whether you are a new system administrator or a seasoned developer, understanding these examples will help you effectively manage your CentOS system’s packages, ensuring it runs smoothly and securely.
In this tutorial you will learn:
- How to install, update, and remove packages
- How to manage package repositories
- Advanced package management operations
Category | Requirements, Conventions or Software Version Used |
---|---|
System | CentOS Linux Distribution |
Software | YUM or DNF package manager |
Other | Internet connection for downloading packages |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Top 20 Package Manager Commands for CentOS
Below are detailed examples and explanations of the most common package management operations you can perform on a CentOS system. These operations will help you maintain the software packages on your system effectively.
CentOS Package Management Cheat Sheet
A quick reference guide for system administrators on using YUM and DNF command-line tools for package management in CentOS.
YUM (Yellowdog Updater, Modified) and DNF (Dandified YUM) are both package managers used in CentOS and other RPM-based Linux distributions, with DNF being introduced as the next-generation version of YUM. While YUM has been the traditional tool for package management, offering capabilities to install, update, and remove packages along with dependency resolution, DNF aims to improve on YUM by offering faster and more accurate dependency resolution, a cleaner, well-structured codebase for easier maintenance, and additional features like automatic synchronization of package metadata. DNF was introduced in Fedora and has been adopted as the default package manager in CentOS 8 and above, marking a significant step forward in the evolution of Linux package management.
# | Task | YUM Command | DNF Command |
---|---|---|---|
1. | Install a package | sudo yum install package_name |
sudo dnf install package_name |
2. | Update a package | sudo yum update package_name |
sudo dnf update package_name |
3. | Remove a package | sudo yum remove package_name |
sudo dnf remove package_name |
4. | Search for a package | yum search keyword |
dnf search keyword |
5. | List all installed packages | yum list installed |
dnf list installed |
6. | Check for available updates | yum check-update |
dnf check-update |
7. | Clean cached data | sudo yum clean all |
sudo dnf clean all |
8. | List enabled repositories | yum repolist |
dnf repolist |
9. | Enable a repository | sudo yum-config-manager --enable repo_name |
sudo dnf config-manager --set-enabled repo_name |
10. | Disable a repository | sudo yum-config-manager --disable repo_name |
sudo dnf config-manager --set-disabled repo_name |
11. | Upgrade all packages | sudo yum upgrade |
sudo dnf upgrade |
12. | Show package information | yum info package_name |
dnf info package_name |
13. | Find which package provides a file | yum provides file_name |
dnf provides file_name |
14. | Check package dependencies | yum deplist package_name |
dnf repoquery --requires --resolve package_name |
15. | Download a package without installing | yum download package_name |
dnf download package_name |
16. | Install a local RPM package | sudo yum localinstall /full/path/to/package_name.rpm |
sudo dnf install /full/path/to/package_name.rpm |
17. | Lock a package version | sudo yum versionlock package_name |
sudo dnf versionlock add package_name |
18. | Unlock a package version | sudo yum versionlock delete package_name |
sudo dnf versionlock delete package_name |
19. | Reinstall a package | sudo yum reinstall package_name |
sudo dnf reinstall package_name |
20. | List all available packages | yum list all |
dnf list all |
- Install a Package: To install a new package on your CentOS system, use the following command. This command will search the configured repositories and install the specified package along with its dependencies.
$ sudo dnf install package_name
This command is fundamental for adding new software to your system.
- Update a Package: Keep your system secure and up-to-date by updating individual packages as follows. This will ensure you have the latest features and security fixes.
$ sudo dnf update package_name
To update all packages, simply omit the package name.
- Remove a Package: If you no longer need a package, you can remove it using the command below. This helps in maintaining a clean system environment.
$ sudo dnf remove package_name
This command will also remove the dependencies that are no longer needed by other packages.
- Search for a Package: Finding the right package can be done by searching the repositories with the following command.
$ dnf search keyword
Replace “keyword” with a relevant term or package name to find.
- List Installed Packages: To see what packages are currently installed on your system, use the command below.
$ dnf list installed
This is useful for auditing or reviewing current software.
- Check for Updates: It’s important to regularly check for package updates to maintain system security and stability.
$ dnf check-update
This command lists all packages that have updates available.
- Clean the Cache: DNF stores downloaded packages and metadata in cache. Cleaning the cache can free up disk space.
$ sudo dnf clean all
This is a good maintenance practice, especially before a backup.
- Install a Package from a Specific Repository: If you have multiple repositories configured, you can specify from which repository to install a package.
$ sudo dnf --enablerepo=repository_name install package_name
This is useful for testing or when a package is only available in a specific repository.
- List Available Repositories: To see which repositories are configured and enabled on your system, use the following command.
$ dnf repolist
This can help you manage where your packages are coming from.
- Enable or Disable Repositories: Control which repositories are used for package management with these commands.
$ sudo dnf config-manager --set-enabled repository_name
$ sudo dnf config-manager --set-disabled repository_name
Enabling or disabling repositories can affect package availability and versioning.
- Upgrade System: To upgrade your entire system to the latest version of all packages, use the following command. This is more comprehensive than updating individual packages.
$ sudo dnf upgrade
This operation can significantly change your system, so use it with caution.
- Show Package Information: Get detailed information about a package, including version, release, and description.
$ dnf info package_name
This is useful for understanding what a package does before installing it.
- Find Which Package Provides a File: If you need a specific file but don’t know which package provides it, use this command.
$ dnf provides file_name
This can be very helpful in resolving dependencies or conflicts.
- Check Package Dependencies: Before installing a package, you might want to check its dependencies.
$ dnf deplist package_name OR $ dnf repoquery --requires --resolve package_name
This command lists all dependencies required by the package.
- Download a Package Without Installing: To download a package and all its dependencies without installing them, use the following command.
$ dnf download package_name
This is useful for manual inspection or installation on another system.
- Install a Local RPM Package: If you have a .rpm file downloaded, you can install it directly with DNF.
$ sudo dnf install /full/path/to/package_name.rpm
This command resolves and installs dependencies from the repositories.
- Lock a Package Version: Prevent a package from being updated accidentally by locking it at a specific version.
$ sudo dnf versionlock add package_name
This ensures stability, especially for sensitive applications.
- Unlock a Package Version: If you need to update a locked package, you can unlock it with the following command.
$ sudo dnf versionlock delete package_name
This restores the ability to update the package.
- Reinstall a Package: To reinstall a package, perhaps to fix a broken installation, use the following command.
$ sudo dnf reinstall package_name
This can be a quick fix for corrupted package installations.
- List All Available Packages: To see every package available in your enabled repositories, use this command.
$ dnf list all
This can help you discover new packages or versions.
Conclusion
Mastering package management on CentOS with YUM and DNF is essential for maintaining a secure, up-to-date, and efficient system. This guide has covered the top 20 most common package manager examples to help you manage your CentOS system more effectively. Whether you’re installing new software, updating existing packages, or managing repositories, these commands will serve as a solid foundation for your package management tasks.