dnf

dnf is the successor of yum and provides some extra functionality whilst keeping many of the same options and syntax. Let's see some examples of how to invoke dnf to get a good grip on the syntax:

# dnf check-update                      -> update the repository metadata
# dnf update                            -> upgrade all installed packages if newer versions are available
# dnf upgrade                           -> same as update
# dnf upgrade libreoffice               -> update just the libreoffice packages
# dnf group update "group_name"         -> update all packages in the given group
.
# dnf search star                       -> search the given string in package name & summary
# dnf search all star                   -> search given string in all package details
.
# dnf list all                          -> list all packages
# dnf list bzip*                        -> list packages matching regex
# dnf list installed                    -> list all installed packages
# dnf list installed bzip*              -> list installed packages that match the regex
# dnf list available                    -> list all available packages
# dnf list available bzip*              -> list avalable packages matching the regex
# dnf list extras                       -> list installed pkgs not available in any known repository
# dnf list obsoletes                    -> list obsolete packages
# dnf list upgrades                     -> list available upgrades for installed packages
# dnf list autoremove                   -> list packages that can be removed because they're no longer required
.
# dnf repolist                          -> list of repositories
# dnf repolist -v                       -> equivalent to "dnf repoinfo" which does not exist
# dnf repolist --enabled                -> list enabled repositories
# dnf repolist --disabled               -> list disabled repositories
.
# dnf info libreoffice                  -> details of package
.
# dnf install package.rpm               -> from repositories
# dnf install /tmp/package.rpm          -> from filesystem
# dnf install wtf-0.5.6-1.fc25.rpm      -> install specific version
# dnf install '@Web Server'             -> install group of packages
# dnf install /usr/bin/tca              -> install rpm that provides the given file
# dnf install https://fedoraproject.org/packages/vim/8.0.314/1.fc25/x86_64/vim-X11-8.0.314-1.fc25.x86_64.rpm
.
# dnf remove libreoffice                -> uninstall package

We can see the list of all dnf invocations with ...

root:/tmp> dnf history list
ID | Command line    | Date and time    | Action(s) | Altered
-------------------------------------------------------------------------------
73 | autoremove      | 2017-02-10 04:00 | Erase   | 31
72 | -y update       | 2017-02-09 17:19 | I, U    | 8
71 | -y update       | 2017-02-08 20:08 | Update  | 18 <
70 | -y update       | 2017-02-07 22:25 | E, I, U | 11 >
69 | -y update       | 2017-02-06 19:27 | Update  | 23 EE
68 | -y update       | 2017-02-02 18:07 | Update  | 5
67 | -y update       | 2017-02-01 19:49 | Update  | 5
66 | -y update       | 2017-01-31 09:48 | E, I, U | 20
65 | -y update       | 2017-01-30 19:35 | Update  | 3
64 | -y update       | 2017-01-30 06:50 | Update  | 68 EE
63 | -y update       | 2017-01-28 20:15 | Update  | 3 EE
62 | -y update       | 2017-01-26 17:11 | Update  | 1
61 | -y update       | 2017-01-25 11:59 | E, I, U | 86 EE
60 | -y update       | 2017-01-21 00:46 | E, I, U | 90
59 | -y update       | 2017-01-19 21:12 | Update  | 62
58 | -y install atop | 2017-01-16 14:04 | Install | 1
57 | -y install htop | 2017-01-16 13:48 | Install | 1
56 | -y update       | 2017-01-16 11:02 | E, I, U | 14
55 | install nmap    | 2017-01-15 22:28 | Install | 1
54 | install hping3  | 2017-01-15 21:59 | Install | 1
53 | -y update       | 2017-01-15 21:47 | I, U    | 71
52 | -y update       | 2017-01-14 03:33 | Update  | 9
51 | -y install ntp  | 2017-01-12 11:30 | Install | 3
50 | -y update       | 2017-01-12 09:58 | E, I, U | 31
[...]

... or we can be a bit more concise ...

root:/tmp> dnf history list 58         -> just show dnf invokation ID 58
root:/tmp> dnf history list 58..70     -> show IDs 58 to 70
root:/tmp> dnf history list *vnc*      -> show those touching packages named *vnc*

We can check the details of a certain dnf run ...

root:/tmp> dnf history info 58
root:/tmp> dnf history info 58..70
root:/tmp> dnf history info *vnc*

We can redo or re-execute a certain transaction ID ...

root:/tmp> dnf history redo 70

We can also rollback the system to the state it was in the past. For instance, if we want to get back all packages to the state they were on the 2nd February 2017 (ID 70), then we can achieve that by executing:

root:/tmp> dnf history rollback 70

We can also undo a specific transaction ID (hopefully the last one to avoid complications!):

root:/tmp> dnf history undo 73

The last history option allows us to see the packages installed by non-root users:

root:/tmp> dnf history userinstalled

A very useful option of dnf is the ability to remove packages that were automatically installed as pre-requisites of another package, but have become unnecessary due to those other packages turning obsolete/removed/upgraded. This clean-up of unnecessary packages can be performed with:

root:/tmp> dnf autoremove 

We can obviously also perform more conventional clean up operations:

root:/tmp> dnf clean dbcache       -> removes cache files generated from repository metadata
root:/tmp> dnf clean expire-cache  -> marks the repository metadata expired so it has to be resynched next time
root:/tmp> dnf clean metadata      -> removes the repository metadata so it has to be downloaded fully next time
root:/tmp> dnf clean packages      -> removes all cached packages from the system
root:/tmp> dnf clean all           -> executes the 4 clean-ups above

In some circumstances we might need to downgrade packages to a lower version because of incompatibilities, bugs, etc. If we do not specify the version we desire, the package/s will be downgraded to the highest version below the current one. But we can state a lower version if we want to ...

root:/tmp> dnf downgrade vim-minimal
root:/tmp> dnf downgrade vim-minimal-2:7.4.1989-2

Sometimes we might want to preserve packages that are not strictly required and would be removed if dnf autoremove. We can do that by marking those packages as user installed with:

# dnf mark install zulucrypt-console-5.0.2-2.fc25.x86_64

We can do the opposite and unmark as user installed a package we do not need and want removed in the next dnf autoremove execution:

dnf mark remove zulucrypt-console-5.0.2-2.fc25.x86_64

As we did with yum, we can query what package provides a certain file:

dnf provides "/usr/bin/echo"

When a package's install is interrupted or some files get corrupted for some reason, we can uninstall and install it again, but it might be easier to just reinstall it:

# dnf reinstall vim-minimal

We can perform operations on all packages of a certain repository using "repository-packages <repoID>" between dnf and the action to perform. Let's see some examples to make sense of it:

# dnf repository-packages google-chrome check-update         -> check for updates only in the google-chrome repo
# dnf repository-packages google-chrome list                 -> list all packages in the "google-chrome" repo
# dnf repository-packages google-chrome list google-chrome*  -> list packages matching the regex
# dnf repository-packages google-chrome list installed       -> list packages installed from this repo
# dnf repository-packages google-chrome list available       -> list packages available in this repo
# dnf repository-packages google-chrome list upgrades        -> list packages that can be upgraded
# dnf repository-packages google-chrome list reinstall       -> reinstall all packages from this repo
# dnf repository-packages google-chrome list remove          -> remove all packages from this repo

The dnf utility uses the settings configured in /etc/dnf/dnf.conf and /etc/yum.repos.d/ seen in the previous section about yum. The latter settings override those laid out in dnf.conf for their specific repositories.

The most commonly used options available in the [main] section are:

assumeyes: as the name implies, it does not prompt for user input and assumes a "yes" answer to any question. Setting this parameter to true might be a bit to gung-ho and I'd advise using the -y flag in the command line to achieve the same effect when required. Default false.

defaultyes: prompts for user input but the default answer (when just pressing Enter) is yes rather than the default no.

clean_requirements_on_remove: remove dependent packages that are no longer in use when running dnf remove. We can specify the packages we do not want removed in such cases by listing them with the parameter installonlypkgs. Default true.

debuglevel: from 0 to 10, it specifies the debugging verbosity. Default 2.

errorlevel: same as debuglevel but applies to error output. Default 2.

exit_on_lock: when set to true (default false) a dnf session will quit immediately if it cannot acquire the lock.

installonlypkgs: list of package names that should only be installed but never upgraded. Kernels by default are included as upgrading a kernel is not a good idea. Instead, we can have up to installonly_limit number of different kernels available to boot in the GRUB prompt. Packages (and kernels) included in this list are not removed not even when they are no longer required and we run dnf autoremove. Minimum should be set to and that's the default value.

installonly_limit: maximum number of versions of a package (or kernel) to keep that are listed in the parameter installonlypkgs.

keepcache: when set to true (default false) it keeps downloaded packages in the cache.

logdir: directory where the log files are kept. Default /var/log.

protected_packages: list of packages that should never be uninstalled. The dnf package and the running kernel are included by default. If we want to add more packages to this list, we should add the name to /etc/dnf/protected.d/dnf.conf. We can also add some other file name with the ".conf" termination to either /etc/yum/protected.d/*conf or /etc/dnf/protected.d/*conf.

rpmverbosity: set to info by default, it specifies the priority of messages sent to the kernel log. It can also be set to critical, warning, emergency, error or debug.

 

The most common parameters used in the [repository] section are:

baseurl: URL where the repository can be found (repodata directory or .repo file). It can be file://, http:// or ftp://.

cost: relative cost of accessing this repository (default 1000). We might set lower values for local repositories or those with high bandwidth and low latency.

enabled: false for disabled (defaults to true for enabled). 

gpgkey: URLs of GPG key files that can be used to sign metadata & packages for this repo. 

metalink: URL of a metalink for the repo.

mirrorlist: URLs of mirrors for the repo.

name: human-readable name for the repo (default to the repoID).

priority: defaults to 99. If a package can be found in more than one repo, the lowest priority one will be used even when a higher package version is available elsewhere.

retries: number of attempts to connect to this repo.

skip_if_unavailable: if set to true (default false), dnf skips repos that cannot be contacted and disables them.

 

<< yum