When using package managers like Yum and DNF on a Linux system, it is important to have control over package updates to prevent unexpected changes to the system. There may be instances where you want to disable or lock package updates to maintain system stability or to prevent specific packages from being updated. Here are four ways to accomplish this:
- Exclude Packages from Updates:
One way to prevent packages from being updated in Yum and DNF is to exclude them from the update process. This can be done by creating a configuration file that lists the packages to exclude. For Yum, create a file named/etc/yum.conf
and add the following lines:
exclude=package1 package2 package3
For DNF, create a file named /etc/dnf/dnf.conf
and add the following lines:
exclude=package1 package2 package3
Replace package1
, package2
, and package3
with the names of the packages you want to exclude from updates.
- Lock Packages:
Another way to disable package updates in Yum and DNF is to lock specific packages to a certain version. This can be done by using theyum versionlock
ordnf versionlock
command. To lock a package in Yum, use the following command:
yum versionlock add package1
To lock a package in DNF, use the following command:
dnf versionlock add package1
This will prevent the specified package from being updated to a newer version.
- Set Package Preferences:
You can also disable package updates by setting preferences for specific packages in Yum and DNF. This can be done by creating a configuration file that specifies the package preferences. For Yum, create a file named/etc/yum.repos.d/example.repo
and add the following lines:
[example]
name=Example Repository
baseurl=http://example.com/repo
enabled=1
gpgcheck=1
priority=1
For DNF, create a file named /etc/yum.repos.d/example.repo
and add the same lines as above.
- Disable Yum or DNF Repository:
If you want to completely disable updates for all packages in Yum or DNF, you can disable the repository that contains the packages. This can be done by editing the repository configuration file and setting theenabled
option to0
. For example, to disable theupdates
repository in Yum, edit the file/etc/yum.repos.d/CentOS-Base.repo
and set the following line:
enabled=0
For DNF, edit the /etc/yum.repos.d/CentOS-Base.repo
file and set the same line as above.
In conclusion, by using these four methods, you can effectively disable or lock package updates in Yum and DNF to maintain system stability and prevent unwanted changes to your Linux system. Just remember to always be careful when making changes to your package manager configuration to avoid any unintended consequences.