Run dnf remove --duplicates but received Unknown argument "--duplicates"

Hi
I referred to Fedora’s official document to upgrade the fedora version.

The following is described in the “Clean-up old packages” section of this document.

But when I executed the command suggested by the documentation:
sudo dnf remove --duplicates
The following prompt message was received:
Unknown argument "--duplicates" for command "remove".

Thanks

The --duplicatesflag works with dnf4, but apparently not with dnf5 (see man dnf remove).

You could run sudo dnf4 remove --duplicates for your specific issue. Does the command sudo dnf repoquery --duplicates return any packages? If it doesn’t, then there is no need to remove any.

Regarding the referred doc, it obviously needs ammended, as it isn’t updated to F41.

2 Likes

You can achieve the same result with this command:

sudo dnf reinstall $(dnf rq --duplicates \
    --latest-limit=1 --qf="%{name}\n")

See also:
Upgrade to 41, "dnf remove --oldinstallonly" doesn't work in dnf5 - #3 by vgaetera

3 Likes
2 Likes

Hi Thank you for your answer. /usr/bin/dnf does link to dnf5.
The sudo dnf repoquery --duplicates command also has no output

1 Like

Thank you

1 Like

I am not so sure.

The point is, that if the update is interrupted before being done, you have an inconsistent rpm database, where some packages appears to be installed multiple times. Thus what needs to be done is remove the record of the oldest package, and make sure the newest version is in a consistent state.

From man rpm of dnf4 you can read:

       dnf [options] remove --duplicates
              Removes older versions of duplicate packages. To ensure  the  integrity
              of  the system it reinstalls the newest package. In some cases the com‐
              mand cannot resolve conflicts. In such cases the dnf shell command with
              remove --duplicates and upgrade dnf-shell sub-commands could help.

Notice that probably the files provided by the new package have already replaced the files that came with the old package, or maybe not, depending on when the process was interrupted.

1 Like

I’m pretty sure it’s basically the same thing since the consistency of the RPM database is ensured by processing transactions through the librpm API.

The meta-information of the database may be inconsistent. But the overall consistency isn’t. When doing a big update, all the install procedures if the new packages are processed one by one, and then all the uninstall procedures of the old packages are processed one by one.

Here’s the relevant piece of code in DNF4:
dnf/dnf/cli/commands/remove.py at e54fcd4dddd6fdfbc167e299d45812a3802c0624 · rpm-software-management/dnf · GitHub

I updated the above command to match it.
Check if I missed anything important.

1 Like

Added docs, docs-todo

It looks like you missed this part

                for pkg in pkgs_list[1:]:
                    self.base.package_remove(pkg)

which goes through the list of duplicates packages from the newest to the oldest skipping the newest package itself. Before that, the newest package is re-installed.

This is intentional as duplicates that cannot be reinstalled should be listed as extras and removed in the next step of the OP’s guide.

In addition, it makes sense to exclude the version tag from the spec passed to the reinstall command.