47

I just switched from Ubuntu to Fedora14. In Ubuntu we had the apt-get autoremove thing to remove orphan/unused packages. What is the counterpart in Fedora?

0

10 Answers 10

40

DNF, the yum replacement since Fedora 22, also provides a autoremove subcommand which is modeled after apt-get/yum autoremove.

Examples:

# dnf autoremove

which tries to remove all automatically installed and otherwise unused dependency packages - should be pretty much equivalent to apt-get autoremove.

# dnf autoremove examplepackage

which removes examplepackage and all its automatically installed (and otherwise unused) dependencies.

Yum

Yum has the autoremove command since Fedora 19, and it is documented since Fedora 20/RHEL 7.

The usage is analogous to the dnf implementation, e.g.:

# yum autoremove

or

# yum autoremove examplepackage

Change the behavior of yum removes

Yum supports a config option to change the default behavior of the remove subcommand (e.g. via /etc/yum.conf):

clean_requirements_on_remove=yes

yum.conf(5)

When this is set, the next yum remove also tries to remove auto installed dependencies iff they are not needed by other packages.

You can also temporarily test this option via something like:

# yum --setopt=clean_requirements_on_remove=1 remove examplepackage

Workaround for old Fedora version

(For Fedora versions where the yum autoremove subcommand is not available and/or clean_requirements_on_remove does not work.)

Although during installation of packages installed dependencies are marked as such (seems to be relatively new feature of rpm/yum).

You can find unneeded dependencies via:

$ package-cleanup --leaves -q --all \
    | xargs repoquery --installed --qf '%{nvra} - %{yumdb_info.reason}' \
    | grep -- '- dep' \
    | cut -d' ' -f1 > tmp

This command line is inspired by fenris02's script.

After inspection of tmp (and perhaps curation) you could remove them via something like this:

# xargs yum remove < tmp
4
  • It gave the error "Invalid yumdb querytag 'reason' for installed pkg: adobe-release-x86_64-1.0-1.noarch". What is this now?
    – c0da
    Feb 11, 2013 at 9:39
  • @c0da, I guess that the feature that yum records in its database the 'reason' of installation (e.g.'dep' or 'user') for each package is relatively new. Perhaps your Fedora instance predates the introduction of that feature such that you have still (a few) old packages installed without that tag set. Feb 11, 2013 at 21:10
  • I installed Fedora 18 a few days back. So I think the required tag should be there.
    – c0da
    Feb 12, 2013 at 9:54
  • 1
    @c0da, perhaps the 'reason' was not recorded because you have installed the package adobe-release via yum localinstall Jul 13, 2013 at 19:15
38

package-cleanup --quiet --leaves from the yum-utils package will list the library packages which aren't relied upon by other packages. Unfortunately it tends to be a bit overeager. On my system, for example, it suggested removing libvirt. Adding the --exclude-bin argument helps. If you're happy with it's suggestion, then to clean up the packages, do:

# package-cleanup --quiet --leaves --exclude-bin | xargs yum remove -y
2
  • 1
    Tested it after installing and removing netbeans-platform and package-cleanup lists some stuff but actually none of the previously installed netbeans-platform dependencies (using Fedora 17). Nov 17, 2012 at 17:51
  • 2
    Doesn't work, as pointed by @maxschlepzig
    – c0da
    Feb 10, 2013 at 4:05
16

you need to install the yum plugin "remove-with-leaves":

# yum install yum-plugin-remove-with-leaves.noarch

once installed:

# yum remove --remove-leaves package

good luck!

3
8
# package-cleanup --orphans >/tmp/junk

edit the /tmp/junk file and remove the first line which is informational from the command line enter the following:

for file in `cat /tmp/junk`
do
  yum remove $file
done
3
  • 1
    package-cleanup(1) says: '--orphans List installed packages which are not available from currently configured repositories.' This is not equivalent to what apt-get autoremove does. apt-get(8) says: 'autoremove is used to remove packages that were automatically installed to satisfy dependencies for some package and that are no more needed.' Nov 17, 2012 at 17:57
  • 1
    Doesn't work! I must have been mistaken previously. Thanks @maxschlepzig
    – c0da
    Feb 10, 2013 at 4:05
  • This used to work for me but in CentOS 6.6 it actually lists all installed packages, not just orphans.
    – Gaia
    Jan 21, 2015 at 18:51
4

NOTE: This answer is correct but only applies to RHEL 7+ and Fedora 20+ (where autoremove has been added as a new feature).

# yum autoremove

Just confirm to remove the selected packages.

0
1

With dnf you can now use for orphans (packages that are not in repositories):

dnf repoquery --extras

and for leaves (unused libraries):

dnf repoquery --unneeded
0

Building upon Larry Mohr's answer:

package-cleanup --orphans | sed '1d' | sed '/^ * /d' | sed '/Loading mirror speeds from cached hostfile/d' | xargs sudo yum remove

(Includes skipping for fastest mirror, if you wonder.)

0

In Fedora, the orphan package means no candidate repos for it to update!

  1. If the orphan packages were generated by you disable yum.repos.d/some.conf.

    yum distro-sync
    
  2. Other orphan packages, the command may be dangerous.

    yum remove $(package-cleanup --orphans)
    

    or, just use the safety command.

    yum remove name-of-page
    
0

Another way to not cause these issues is to to use transactions.

After setup base system, as you install using yum, it creates transactions. When you intend to remove things, rollback the transactions.

https://docs.fedoraproject.org/en-US/Fedora/24/html/System_Administrators_Guide/sec-DNF-Transaction_History.html

0
yum -y remove $(package-cleanup --orphans | sed -n '/*/,//p' | grep -v \*)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .