
Table of Contents Introduction According to the Linux manual pages (man yum), there are 35 standard YUM commands. That number increases to the hundreds when
Learn how to automatically exclude packages using DNF on Linux-based systems. This guide covers DNF exclusion options, CLI examples, and strategies for managing package installations effectively.
The DNF (Dandified YUM) package manager is a powerful tool for managing software packages on Fedora, CentOS, RHEL, and other RPM-based distributions. It helps users install, update, remove, and manage software packages efficiently. One common need for system administrators and developers is to prevent certain packages from being installed or updated automatically. This is where DNF’s exclude feature comes into play.
This blog post will explain how to automatically exclude packages using DNF, focusing on the practical steps you need to follow. We’ll dive into various methods, explore real-world examples, and show how you can fine-tune your DNF configuration to suit your specific requirements.
DNF comes with a built-in exclusion mechanism that prevents specific packages from being installed, upgraded, or removed. Exclusion is useful in scenarios where you want to avoid breaking a working configuration by ensuring certain software versions stay locked or specific packages are kept from being upgraded.
For example, you might want to exclude a package from an update cycle because it’s not compatible with your current system setup or a newer version of the package introduces issues. Or, you may need to exclude a package that conflicts with other software in your environment.
DNF allows you to exclude packages both temporarily (for a specific command) and permanently (through configuration changes). Both methods offer flexibility, and in this guide, we’ll cover both approaches.
Sometimes, you may not want to permanently exclude a package but need to prevent its installation or upgrade for a specific command. DNF allows you to do this with the --exclude
flag.
CLI Example |
Suppose you want to install updates, but you need to exclude a package named httpd
from being updated. You would run the following command:
sudo dnf update --exclude=httpd
This command will update all packages except httpd
. You can specify multiple packages separated by commas if you need to exclude more than one:
sudo dnf update --exclude=httpd,nginx
|
|
If you need to exclude packages across all DNF operations (including updates, installs, etc.), it’s best to configure DNF to permanently exclude specific packages. This is done by modifying the DNF configuration file (/etc/dnf/dnf.conf
), which controls DNF’s behavior.
Steps to Exclude Packages Permanently |
Open the DNF configuration file for editing.
sudo vim /etc/dnf/dnf.conf
Locate or add the exclude
line under the [main]
section.
If the exclude
line is not present, you can add it manually. For example, to exclude the httpd
package, you would add the following:
[main]
exclude=httpd
To exclude multiple packages, separate them with spaces:
[main]
exclude=httpd nginx mysql
sudo dnf update -y
|
|
Excluding packages during an update or installation can be critical when managing servers or specific software stacks. Let’s walk through a couple of practical use cases.
Example 1: Preventing a Package Update |
To prevent a specific package from being updated (such as httpd
), you can use the --exclude
flag during the dnf update
process:
sudo dnf update --exclude=httpd
Example 2: Preventing Package Installation |
If you’re installing packages and want to ensure a specific package is never installed (even if it’s a dependency), use the --exclude
option like this:
sudo dnf install nginx --exclude=httpd
This will install nginx
but prevent httpd
from being installed, even if it’s a dependency for nginx
.
Another useful feature in DNF is the ability to manage groups of packages (e.g., development tools, web servers). You can combine the exclusion functionality with DNF’s group management to fine-tune the software installed on your system.
Example: Excluding a Package from a Group |
Imagine you are installing a group of packages but want to exclude one or more specific packages from being installed. The command would look like this:
sudo dnf groupinstall "Development Tools" --exclude=clang
This will install all packages in the “Development Tools” group except clang
.
DNF Command | Description |
---|---|
sudo dnf groupinstall "Development Tools" | Installs all packages in the “Development Tools” group |
sudo dnf groupinstall "Development Tools" --exclude=clang | Installs “Development Tools” group, excluding clang |
sudo dnf groupremove "Development Tools" | Removes all packages in the “Development Tools” group |
Excluding packages can have an impact on both system performance and stability. Excluding essential security updates or vital packages can lead to vulnerabilities and system issues. Therefore, use exclusions judiciously.
Here are some important considerations:
|
|
|
Always review exclusions carefully to ensure they align with your system’s stability and security requirements.
Here are some troubleshooting steps for issues you may encounter when using the exclude feature:
Problem 1: Package Still Being Installed After Exclusion |
If a package is still being installed despite being excluded, check the following:
|
|
|
Problem 2: Dependencies Not Being Excluded |
If a package that is a dependency of another one is still being installed, you may need to exclude it individually, as exclusions do not automatically apply to dependencies.
Excluding packages in DNF is an effective way to manage which software is installed or updated on your Linux system. By understanding both temporary and permanent exclusion methods, you can maintain control over your environment while avoiding potential issues with package dependencies or unwanted updates. Remember to carefully monitor exclusions, especially when it comes to security-critical packages.
Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.
Table of Contents Introduction According to the Linux manual pages (man yum), there are 35 standard YUM commands. That number increases to the hundreds when
In this article, we will review the most commonly used RPM commands in Linux. These commands play a pivotal role in package management, allowing users
Learn how to inspect and extract RPM package contents using various tools like rpm, rpm2cpio, and repoquery. Discover detailed examples and best practices for managing