What is Fedora's equivalent of 'apt-get purge'?
Solution 1
yum remove
is not guaranteed to preserve configuration files.
As stated in the yum HOWTO:
In any event, the command syntax for package removal is:
# yum remove package1 [package2 package3...]
As noted above, it removes package1 and all packages in the dependency tree that depend on package1, possibly irreversibly as far as configuration data is concerned.
Update
As James points out, you can use the rpm -e
command to erase a package but save backup copies of any configuration files that have changed.
For more information, see Using RPM to Erase Packages. In particular:
It checks to see if any of the package's config files have been modified. If so, it saves copies of them.
Solution 2
I found this answer to a duplicate question on ServerFault titled: yum equivalent of “apt-get purge" that provides the only method I've seen that can do what apt-get purge <pkg>
does on Ubuntu/Debian.
for package in package1 package2 package3
do
echo "removing config files for $package"
for file in $(rpm -q --configfiles $package)
do
echo " removing $file"
rm -f $file
done
rpm -e $package
done
The only other method I can conceive of here is to parse the output from yum remove <pkg>
and then manually delete any files that may have been modified. For example when I recently installed ElasticSearch's RPM for 2.3 I modified several files that were associated with this RPM. When I removed it with YUM you'll get messages in the output like this:
warning: /etc/sysconfig/elasticsearch saved as /etc/sysconfig/elasticsearch.rpmsave
warning: /etc/elasticsearch/logging.yml saved as /etc/elasticsearch/logging.yml.rpmsave
warning: /etc/elasticsearch/elasticsearch.yml saved as /etc/elasticsearch/elasticsearch.yml.rpmsave
These can be deleted post removal using YUM either scripted or by hand.
Reference
Solution 3
For Fedora 31:
Uninstall:
sudo dnf remove PACKAGE
Clean caches and other not needed files (not this is not the same as purge as far as I understood it)
sudo dnf clean all
To get more information about the command (before you execute the above):
dnf clean
This does nothing but show you the help screen for the clean command. Read also the manual, sometimes they are worth the time.
man dnf
For first time man users:
- press / to start searching
- type clean, press return
- press n until you are in the section
- note: In this case you could also just search for Clean Command but without knowing anything about the manual this would be not so easy.
See also:
- /etc/dnf/dnf.conf -> setting clean_requirements_on_remove for a setting related to the asked operations
-
see
man dnf.conf
clean_requirements_on_remove boolean
Remove dependencies that are no longer used during dnf remove. A package only qualifies for removal via clean_requirements_on_remove if it was installed through DNF but not on explicit user request, i.e. it was pulled in as a dependency. The default is True. (installonlypkgs are never automatically removed.)
Related videos on Youtube
tshepang
I do software development for a living and as a hobby. My favorite language is Rust, and I've used Python much in the past. My OS of choice is Debian.
Updated on September 17, 2022Comments
-
tshepang almost 2 years
In Debian, there's at least two ways to delete a package:
apt-get remove pkgname
apt-get purge pkgname
The first preserves system-wide config files (i.e. those found in "/etc"), while the second doesn't.
What is Fedora's equivalent of the second form,
purge
? Or maybe I should rather ask ifyum remove pkgname
actually preserves config files. -
Admin over 13 years
-
Erik5388 over 13 yearsThat's not really true, "rpm -e" will remove the configuration files if they haven't changed. If they have been changed they are moved to <filename>.rpmsave and not deleted.
-
Admin almost 12 years@Gilles Justin Ethier says
yum remove
is "not guaranteed to preserve configuration files." That's not the same as saying that it is guaranteed not to preserve configuration files (which would mean it is equivalent toapt-get purge
). Are you making this (much) stronger claim? -
Admin almost 12 years@EliahKagan That's the way I understand the yum howto that Justin cites. I'm not sure that it's right, the CentOS seems to be saying the opposite.
-
mattdm almost 8 yearsThis might be an interesting dnf plugin....
-
slm almost 8 years@mattdm - this issue has come up from time to time, would be nice if we could do this in the "RPM" world.
-
m0j0 over 5 yearsThis is incorrect. The "yum clean all" merely cleans up cached metadata, mirror lists, etc., used by yum. It does nothing to configuration files.
-
Admin over 5 yearsI think it's undefined behavior. Yum may or may not preserve configuration files.