Introduction
Package managers are essential tools for software management in all Linux distributions. The primary package manager for Rocky Linux is DNF, but it also supports several other alternatives, including RPM and Flatpak.
Knowing how to use a package manager enables system administrators to install, update, and manage applications on Rocky Linux efficiently. Packages help create a functional environment for your system.
This guide shows how to use different package managers in Rocky Linux.
Prerequisites
- Access to the command line/terminal.
- A user with sudo privileges.
Note: See how to create a sudo user on Rocky Linux and CentOS.
How to Use DNF Package Manager in Rocky Linux
The DNF (Dandified Yum) package manager is the default software management tool in Rocky Linux. The tool installs, updates, and removes packages. It is the heir to the YUM package manager.
DNF simplifies package management by automatically checking for software dependencies and taking the required actions during installation. It eliminates manual updates and dependency management. When working with packages, DNF performs the following steps:
- Queries repositories. DNF connects to the repositories defined in the /etc/yum.repos.d/ directory.
- Resolves dependencies. Before installing or updating, DNF checks for dependencies and ensures they are available. It defines the required actions to resolve dependencies.
- Handles transactions. DNF prepares and validates a transaction by defining each package's operation (download, install, remove, or update).
- Downloads and installs. The package manager downloads the required files and applies all operations. GPG keys help verify package authenticity in this step.
- Manages cache. DNF keeps a cache of package metadata and downloaded packages to speed up future queries. Cleaning this cache helps free up disk space when required.
- Logs data. The package manager logs which packages were installed, updated, or removed to help track system changes over time.
Continue reading to see how to use DNF on Rocky Linux.
How to Install Packages
To install a package on Rocky Linux, use:
sudo dnf install [package-name]
Press Y to confirm the package download and approve the GPG key if requested. After this, the download and installation start. Once completed, the package is available for use.
How to List Installed Packages
To show already installed packages on the system, run:
sudo dnf list installed
The command lists all installed packages. It shows each package's name, version, and repository source.
How to Update Packages
Update all installed packages on Rocky Linux with:
sudo dnf update
The command checks for any available updates for all installed packages. The terminal lists the packages and prompts for confirmation if there are available updates. Press Y to continue.
How to Search Packages
To search for a specific package, use:
sudo dnf search [package-name]
Replace [package-name]
with the full or partial name of the package you want to find. The command returns a list of matching packages along with their description.
How to View Package Details
To see detailed information for a package, run:
sudo dnf info [package-name]
The output shows the package name, version, repository source, and description.
How to Remove Packages
Uninstall a package with:
sudo dnf remove [package-name]
Provide the actual package to be removed. The system prompts to confirm the removal of the package. The command also removes dependencies that are no longer required.
How to Manage Repositories
To list enabled repositories on the system, use:
sudo dnf repolist
The command lists the repository ID and name.
For a more detailed list, run:
sudo dnf repolist all
The command lists all repositories, showing their status as either enabled or disabled in the final column.
Use the following commands to enable or disable a repository:
- Enable:
sudo dnf config-manager --set-enabled [repository-name]
- Disable:
sudo dnf config-manager --set-disabled [repository-name]
The commands change the package's status accordingly.
How to Clear DNF Cache
Free up space by clearing the cached metadata and package information:
sudo dnf clean all
The command removes all cached files in the /var/cache/dnf/ directory and shows how many were removed.
How to Work with Package Groups
Rocky Linux allows working with package groups. These groups are a collection of related software packages designed for a specific use case or task. They aim to simplify installing package sets that are commonly used together (such as a development environment, web server, etc.).
To list available package groups, enter:
sudo dnf group list
The groups have descriptive names and are categorized into environment and regular software groups.
To install a package group, use:
sudo dnf group install "[group-name]"
Replace the placeholder with the actual group name. If the name contains spaces, put the name in quotes.
Remove a package group with:
sudo dnf group remove "[group-name]"
The command removes all packages from the provided group.
DNF Package Manager Alternatives for Rocky Linux
Although DNF is the default package manager for Rocky Linux, there are also alternative systems for software management. Below are two popular alternatives: RPM and Flatpak.
RPM
RPM (Red Hat Package Manager) is the underlying package management system for Red Hat-based distributions, including Rocky Linux. The tool works with .rpm package files and provides essential functionality for package management:
- Install a package:
sudo rpm -i [package-file.rpm]
- List installed packages:
rpm -qa
- Update a package:
sudo rpm -U [package-file.rpm]
- Search for a package:
rpm -q [package-name]
- Remove a package:
sudo rpm -e [package-name]
Note: For more details, check out our in-depth rpm command guide.
Flatpak
Flatpak is a system for managing applications in isolated environments. It's available on different distributions and provides a consistent experience regardless of the Linux system. Flatpak contains all the required package management commands:
- Install a package:
sudo flatpak install [repository] [package-name]
- List installed packages:
flatpak list
- Update installed packages:
sudo flatpak update
- Search for a package:
flatpak search [package-name]
- Remove a package:
sudo flatpak uninstall [package-name]
DNF vs. RPM vs. Flatpak
Choosing between DNF, RPM, and Flatpak depends on your specific requirements and preferences. Each tool is suitable for specific scenarios:
- DNF. The package manager is ideal for most package management tasks. It automatically handles dependencies, provides access to repositories, and offers advanced functionalities through group management. DNF is the go-to choice for everyday package management tasks.
- RPM. The tool is best for managing individual .rpm packages. It's fast and lightweight, but it does not resolve dependencies automatically. RPM is best for managing and installing specific files without relying on repositories.
- Flatpak. Applications that require functionality across different Linux systems benefit from using Flatpak as a package management tool. It runs in isolated environments and reduces conflicts with system packages. Use Flatpak for cross-distribution compatibility or desktop applications.
Conclusion
This guide explained how to use DNF on Rocky Linux. It also provided a brief overview of alternative package management tools (RPM and Flatpak) and explained when to use each.
Next, see our in-depth comparison between Flatpak vs. Snap vs. AppImage.