As I was exploring about Fedora 22 (I'm currently using fedora 20), I came to learn that Yum has been replaced by DNF. Basically what I want to know is the difference between those two Fedora package managers and the reason for this change.
Fedora 22 – Yum vs DNF Package Managers
dnffedorayum
Related Solutions
Since Fedora 26, the Dnf repoquery
subcommand supports has a new option for listing all user-installed packages:
$ dnf repoquery --qf '%{name}' --userinstalled \
| grep -v -- '-debuginfo$' \
| grep -v '^\(kernel-modules\|kernel\|kernel-core\|kernel-devel\)$' > pkgs_a.lst
In contrast to other methods, it also lists all debuginfo packages. The additional grep in the above example filters them out.
To install the list on host B:
$ < pkgs_a.lst xargs dnf -y install
Dnf API
With recent Dnf versions (e.g. Fedora >= 23), the package database can be queried for user installed package names via the Dnf Python API:
$ python3 -c 'import dnf; b = dnf.Base(); b.fill_sack(); \
l = sorted(set(x.name for x in b.iter_userinstalled() \
if not x.name.endswith("-debuginfo") \
and x.name not in \
["kernel-modules", "kernel", "kernel-core", "kernel-devel"] )); \
print("\n".join(l)) ' > pkgs_a.lst
# dnf install $(cat pkgs_a.lst) # on host_b
By default, dnf install
aborts if one or more packages aren't available anymore. Alternatively, dnf can be forced to install all remaining ones:
# dnf install --setopt=strict=0 $(cat pkgs_a.lst) # on host_b
PS: Put the above code and more into user-installed.py
that also supports other distributions.
history userinstalled
On Fedora 23 and later, Dnf provides the
# dnf history userinstalled
command that lists all user installed packages. As of 2016-11, its usefulness is limited because there is no way to control its output and it prints packages fully qualified (i.e. including version information).
userinstalled Limitations
Note that the marking of packages as user-installed has some limitations on some Fedora versions, for Fedora 23-ish era systems (from around 2015-11) the following issues are relevant):
- packages installed via the GUI are not included
- packages installed via the command-not-found handler are not included
- some packages installed by default (by anaconda) are included
Repoquery
On older Fedora systems, where Dnf, the Dnf API and dnf history userinstalled
aren't available, one can use repoquery instead, e.g.:
$ repoquery --installed \
--qf '%{n} | %{yumdb_info.reason} | %{yumdb_info.installed_by}' --all \
| awk -F'|' ' $2 ~ /user/ && ($3 != 4294967295) { print $1 }' \
| sort -u > pkgs_a.lst
The second awk condition is used to exclude packages that were installed by the installer. The installer's user-id was apparently stored as 4294967295 - alternatively you can write something like ($3 == 0 || $3 == your-user-id)
.
Note that this command works on Fedora up to release 21 - but e.g. not on release 23, because the command repoquery
was replaced with dnf repoquery
. And dnf repoquery
does not understand the %{yumdb_info.reason}
tag.
While common package managers don't address this use case, there are several projects that do:
- Zero Install
- Linuxbrew - a port of Homebrew for Linux
- Gentoo Prefix
- Nix
- pkgsrc - can be used to install packages as an unprivileged user according to somebody's blog post
My best guess as to why traditional package managers don't address this use case is that it greatly complicates the package building and installation process, since package maintainers will need to be very careful to ensure that their packages correctly support a dynamic installation directory. In fact, many common package formats such as RPM support a dynamic installation directory, but hardly any maintainers take advantage of this feature when building packages due to the high additional overhead.
Best Answer
Compared to Yum, DNF offers:
See Will DNF Replace Yum?