Remove older versions of installed packages with DNF
dnf remove $(dnf repoquery --installed --latest-limit=-2 -q)
Removes all but the latest installed 2 versions of packages using dnf repoquery to find older versions and dnf remove to uninstall them.