Need help with dnf commands for listing and installing packages to & from a txt file

I have got a fedora 34 machine on which I will be doing a fresh install of fedora 36, but I don’t wish to loose all important packages that I have installed.

So is there a way to save all explicitly user installed package names to a txt file,
and install these packages from the list with a single command on the fresh machine… like can be done on other distros.

Sure:

rpm -qa --qf '%{Name}.%{Arch} ' > file-list.txt

Then dnf install $(cat file-list.txt) on the new system, keeping in mind that this depends on the same repos/rpms being present and doesn’t account for package renames.

2 Likes

The command dnf repoquery --userinstalled > ~/installed-packages.txt will give you a file with all the names of packages that were user installed. If you save that file before you do the new install then it can be used to do the new install of those packages on the newly installed F36.

Note that the file names saved will include the version number and distro for which they were installed, so you will need to do a bit of tweaking on the file list to avoid the errors that would result from trying to install fedora 34 packages and versions on fedora 36.

In other words, the command would return a list something like this

xsane-0:0.999-41.fc35.x86_64
xsane-common-0:0.999-41.fc35.x86_64
xsane-gimp-0:0.999-41.fc35.x86_64

and you would need to modify it to something like this before doing the new install so the appropriate fedora 36 package would be installed.

xsane
xsane-common
xsane-gimp

Note that the command given by @vwbusguy above would work similar with a slight modification to read rpm -qa --qf '%{Name} ' > file-list.txt and that it would return a list of all packages installed, not just the user-installed ones.

3 Likes

Note that my command above includes the arch, in order to support multilib versions of things. Less important now than it used to be, but still an important distinction if you run stuff with wine or cross-compile, etc. This is the method I normally use to reinstall packages after a fresh install.

1 Like

Your command returned several for me with the package-name.(none) form. How would you do the install of those?

Oh hey, you’re right! Here you go:

rpm -qa --qf '%{Name}.%{Arch} ' | sed 's,\.(none),,g' > file-list.txt