My YUM and DNF cheatsheet

Home

1 YUM and DNF are not the only package managers.

2 YUM Yellow-dog Updater Modifier

Used by RPM, and since CentOS is "Community Enterprise OS" which is a fork of off Red Hat Enterprise, it makes sense that CentOS would be using YUM. However, YUM had some performance issues, so has been getting replaced by Dandified YUM, or DNF or just Dandified. See 2daygeek

In fact readthedoc.io claims that the next major release of YUM is DNF.

3 YUM is deprecated into DNF "Dandified Yum"

3.1 Common DNF commands

  • dnf check-update # looks at ALL packages that have available updates
  • dnf check kernel-core.x8664
  • dnf clean
  • dnf clean packages
  • dnf clean all
  • dnf-command(versionlock) # installs a versionlock plugin
  • dnf deplist
  • dnf distro-sync
  • dnf downgrade
  • dnf download httpd # this won't work until you add the DNF plugin
  • dnf install dnf-plugins-core
  • dnf download httpd # now will work
  • dnf help
  • dnf help install
  • dnf history
  • dnf info vim emacs vi
  • dnf install httpd -y # will assume 'yes' on all prompts to install
  • dnf install
  • dnf list
  • dnf list installed
  • dnf list available
  • dnf list pip3
  • dnf makecache
  • dnf mark
  • dnf modules
  • dnf provides
  • dnf reinstall json-glib.x8664
  • dnf remove httpd # this is your uninstall.
  • dnf reinstall httpd -y
  • dnf repoinfo
  • dnf repoquery
  • dnf repolist
  • dnf repository-packages
  • dnf shell
  • dnf search
  • dnf swap
  • dnf updateinfo
  • dnf upgrade # this is preferred as it works like yum –obsoletes update
  • dnf upgrade -y # answers "yes" to all prompts
  • dnf update # this works like yum update, so use dnf upgrade instead.
  • dnf upgrade bash
  • dnf upgrade-minimal
  • dnf upgrade-to
  • dnf --version
  • dnf grouplist # CentOS lets you install groups of apps together. Easier.

.

If you have .rpm files, they can be install using rpm commands, but you could also run:

  • dnf install unbout-21.4.20-29.e17.x8664.rpm
  • dnf info xxx
  • sudo dnf info qemu-kvm qemu-img virt-manager libvirt libvirt-python

3.1.1 dnf list

  • dnf list --available [<package-name-specs>...]
  • dnf list --installed
  • dnf list --upgrades

Remember to man dnf (man yum works as well, as it redirects to dnf)

  • sudo yum list --showduplicates 'tar.*'
  • sudo yum list --showduplicates '*net-tools*'

3.1.2 dnf provides /usr/sbin/semanage

dnf provides /usr/sbin/semanage This will find out which package provides the file called /usr/sbin/semanage

will tell you the package that you need to install to get semanage For me it was: policycoreutils-python-utils-2.9-3.el81.1.noarch so I used: dnf install policycoreutils-python-utils-2.9-3.el81.1.noarch (pay attention to .el8 vs el7 One is for CentOS8 the other for CentOS7)

4 Log of dnf commands run on the CentOS

dnf list –installed dnf install tcshhiishi

5 Add a new repository

We can specify a new repository by manually editing or creating a new .repo file in the /etc/yum.repos.d directory, however we can much more easily create a persistent repository with the dnf config-manager command.

Adding repo from: https://mirror.aarnet.edu.au/pub/centos/7

  • dnf config-manager --set-enabled PowerTools # this failed
  • dnf config-manager --set-enabled powertools # this worked
  • dnf config-manager --set-enabled powertools

followed by confirmation:

  • dnf repolist

cat /etc/yum.repos.d/mirror.aarnet.edu.au_pub_centos_7.repo [mirror.aarnet.edu.aupubcentos7] name=created by dnf config-manager from https://mirror.aarnet.edu.au/pub/centos/7 baseurl=https://mirror.aarnet.edu.au/pub/centos/7 enabled=1

We simply provide a known repository URL in the –add-repo option, and this creates a .repo file based on the name of the repository URL specified. In this case, /etc/yum.repos.d/mirror.aarnet.edu.aupubcentos7.repo has been created with the contents specified above in the output of the command. We can now install or update packages from this newly specified mirror.

The following command also seemed to add a repo. Not sure if this is the same thing or a different approach to "–add-repo"

  • dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

5.1 EPEL Repository makes it easier to add itself as a repo

With EPEL, they included a package, epel-release that adds EPEL as a repo. so all you need is sudo dnf install epel-release Then also dnf search epel to search for it and also dnf info epel-release

Once epel is installed, enable the PowerTools as EPEL packages may rely on it

  • sudo dnf config-manager --set-enable PowerTools ( or "powertools" lowercase)
  • sudo dnf config-manager –help
  • sudo dnf

If config-manager does not work, you can fix it by adding: dnf install 'dnf-command(config-manager)' And then rerun the above commands. as well as dnf upgrade or yum update

5.2 Check if repo added:

  • dnf repolist epel ( or just dnf repolist )
  • dnf repolist
  • dnf repolist
  • dnf repolist
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf install epel-rlease
  • dnf install epel-rlease
  • dnf install epel-rlease
  • dnf install epel-rlease
  • dnf install epel-rlease
  • dnf install epel-rlease
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf repolist –all
  • dnf info epel-release
  • dnf install epel-release

5.3 Other repos just add the URL to:

dnf config-manager --add-repo"https://centos.pkgs.org/8/centos-powertools-x86_64/" If config-manager gave you an error, you can fix it by dnf install 'dnf-command(config-manager)'

5.4 Removing a repo from my list

Before removing a repository from yum, you should check if the repository was installed NOT by yum but straight as an rpm. Many repos like RPM-Fusion and EPEL are installed using rpm.

Search for it using rpm -qa | grep -i repo-name For example: sudo rpm -qf /etc/yum.repos.d/epel.repo

If RPM is found, then simply remove the whole RPM packing using: rpm -e repo-I-want-delted-rpm-package

Then if RPM was NOT found, simply remove the repo file itself: rm /etc/yum.repos.d/repos-file.repo OR rename is so it does not end in .repo Somehting like .repo.orig will do.

  1. yum remove epel-release

    This may also work. Follow that with yum clean all

5.4.1 dnf config-manager –help

Looking for a way to remove a repo from my repolist: dnf config-manager –disablerepo ? # this temporarily disables it only. dnf config-manager –disablerepo 'centos.pkgs.org8centos-powertools-x8664_' so far did not work…most likely because I had not added the command to yum dnf install 'dnf-command(config-manager)' should fix that.

Since apparently yum itself cant' do it, you need yum-config-manager, then Another possible approach: yum-config-manager –disable repository yum-config-manager –add-repo "https://centos.pkgs.org/8/centos-powertools-x86_64/"

  1. dnf config-manager –disablerepo [repo]

    where you get the repo from repolist output.

5.4.2 Manually editing /etc/yum.repos.d

It appears that all you have to do is delete the actual file in: /etc/yum.repos.d/*.repo followed by a sudo dnf repolist –refresh

In order to remove the actual yum repository rather than just to disable it, you have to find the package and remove it.

rpm -qa | grep epel
get the output then:
yum remove epel-release-5-4
yum clean all

5.4.3 sequence of cleaning repos:

So to clean all the cached packages from the enabled repository cache directory, login as root and execute the following:

sudo dnf clean packages

To purge the old package information completely, execute the following command:

yum clean headers. ...
yum clean metadata. ...
yum clean all.
  1. dnf clean

    According to this reddit post, "Dnf stores information about what packages are available for a couple hours so that you don't have to go out and download all of that every time you run a command. Clean all tells it to forget about that cached information. Once the cache is cleaned, the next call to update has to go out and fetch that information. In your case, there were new packages available while your cache was still considered fresh. If you had waited a couple hours, dnf update would've seen them without you having to run dnf clean all."

    And just to clarify, if all you want to do is to have dnf check for updates right now, use the --refresh flag: dnf update '*' --refresh. dnf clean all deletes a bunch of repository data, including already-downloaded updates, that you may want to keep around.

5.5 Disabling a repo (but keeping it around)

Rather than removing it altogether, you could disable (and later enable) a repo like this

  1. Edit /etc/yum.repos.d/repo-in-question.repo and change the enabled option to 0 i.e. change enabled=1 to enabled=0 for my CentOS linux,
  2. renable it quickly with dnf --enablerepo=repo-in-question install some-package
  3. disable via the yum-config-manager –disable repo-in-question command
    • yum-config-manager --disable repo-in-question
    • dnf config-manager --disablerepo repo-in-question
  4. disable yum repo using yum/dnf yum --disablerepo=repo-in-question install some-package dnf exact same command.
  1. From online:

5.6 Where are these repos?

There seem to be various different ways of adding a repo. For instance, the powertools repo has these possibilities

5.6.1 yum install dnf-plugins-core

5.6.2 yum config-manager –set-enabled PowerTools

5.6.3 yum repolist

Another way to enable power-tools is: sudo dnf install dnf-plugins-core

5.6.4 dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

That installs the epel release.

5.7 Powertools for CentOS (needed to get lynx)

Centos.pkgs.org had a very good tip on installing lynx. First, it had the binary package of lynx, for CentOS 8, and second, it had tips on how to install it using dnf. Specifically: Install Howto Install lynx rpm package:

dnf –enablerepo=PowerTools install lynx

This could be done in two steps.

  1. dnf enable the PowerTools repo with dnf –enable repo=PowerTools
  2. dnf install lynx

5.7.1 As of April 21, 2021 slight change

I had to dnf install dnf-plugins-core followed by dnf config-manager --set-enabled powertools

root@zinux ~[606]$
dnf install dnf-plugins-core
Last metadata expiration check: 0:53:35 ago on Tue 20 Apr 2021 03:38:29 PM EDT.
Package dnf-plugins-core-4.0.17-5.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
root@zinux ~[607]$
dnf config-manager --set-enabled powertools
root@zinux ~[608]$

Then I successfully dnf install lynx and

5.7.2 Manually enabling PowerTools

Edit the PowerTools repo file

  • vim /etc/yum.repos.d/CentOS-PowerTools.repo
  • Change enabled=0 to enabled=1

For instance, this was what my zintis.net host has

root@zinux /etc/yum.repos.d[618]$
grep "enabled=" *.repo
CentOS-Linux-AppStream.repo:enabled=1
CentOS-Linux-BaseOS.repo:enabled=1
CentOS-Linux-ContinuousRelease.repo:enabled=0
CentOS-Linux-Debuginfo.repo:enabled=0
CentOS-Linux-Devel.repo:enabled=0
CentOS-Linux-Extras.repo:enabled=1
CentOS-Linux-FastTrack.repo:enabled=0
CentOS-Linux-HighAvailability.repo:enabled=0
CentOS-Linux-Media.repo:enabled=0
CentOS-Linux-Media.repo:enabled=0
CentOS-Linux-Plus.repo:enabled=0
CentOS-Linux-PowerTools.repo:enabled=1
CentOS-Linux-Sources.repo:enabled=0
CentOS-Linux-Sources.repo:enabled=0
CentOS-Linux-Sources.repo:enabled=0
CentOS-Linux-Sources.repo:enabled=0
root@zinux /etc/yum.repos.d[619]$

5.8 Adding brave-browser-rpm repository

sudo dnf config-manager –add-repo https://brave-browser-rpm-beta.s3.brave.com/x86_64/

6 More repo commands:

To add a repository we use: sudo dnf –add-repo <reponame>

To enable repository transiently: sudo dnf –enablerepo=<reponame> sudo dnf enable the PowerTools repo with dnf –enablerepo=PowerTools

To disable repository transiently: sudo dnf –disablerepo=<reponame>

To disable repository permanently: sudo dnf config-manager –set-disabled <reponame>

To enable repository permanently: sudo dnf config-manager –set-enabled <reponame>

To remove a repository, first check if a package used is part of the repo then if not, can simply delete the file in /etc/yum.repos.d/*.repo

7 Many more dnf commands

Are available here: rootusers.com

8 YUM commands:

See the pdf.

9 Sample dnf from CentOS 8


 zintis@c8host ~$ sudo dnf info qemu-kvm qemu-img virt-manager libvirt libvirt-python
 Installed Packages
 Name         : qemu-img
 Epoch        : 15
 Version      : 2.12.0
 Release      : 65.module_el8.0.0+189+f9babebb.5
 Arch         : x86_64
 Size         : 4.7 M
 Source       : qemu-kvm-2.12.0-65.module_el8.0.0+189+f9babebb.5.src.rpm
 Repo         : @System
 From repo    : Aptream
 Summary      : QEMU command line tool for manipulating disk images
 URL          : http://www.qemu.org/
 License      : GPLv2 and GPLv2+ and CC-BY
 Description  : This package provides a command line tool for manipulating disk images.

 Name         : qemu-kvm
 Epoch        : 15
 Version      : 2.12.0
 Release      : 65.module_el8.0.0+189+f9babebb.5
 Arch         : x86_64
 Size         : 0.0  
 Source       : qemu-kvm-2.12.0-65.module_el8.0.0+189+f9babebb.5.src.rpm
 Repo         : @System
 From repo    : AppStream
 Summary      : QEMU is a machine emulator and virtualizer
 URL          : http://www.qemu.org/
 License      : GPLv2 and GPLv2+ and CC-BY
 Description  : qemu-kvm is an open source virtualizer that provides hardware
              : emulation for the KVM hypervisor. qemu-kvm acts as a virtual
	      : machine monitor together with the KVM kernel modules, and emulates the
	      : hardware for a full system such as a PC and its associated peripherals.

 Available Packages
 Name         : libvirt
 Version      : 4.5.0
 Release      : 24.3.module_el8.0.0+189+f9babebb
 Arch         : x86_64
 Size         : 26 k
 Source       : libvirt-4.5.0-24.3.module_el8.0.0+189+f9babebb.src.rpm
 Repo         : AppStream
 Summary      : Library providing a simple virtualization API
 URL          : https://libvirt.org/
 License      : LGPLv2+
 Description  : Libvirt is a C toolkit to interact with the virtualization capabilities
              : of recent versions of Linux (and other OSes). The main package includes
	      : the libvirtd server exporting the virtualization support.

 Name         : virt-manager
 Version      : 2.0.0
 Release      : 5.1.el8
 Arch         : noarch
 Size         : 365 k
 Source       : virt-manager-2.0.0-5.1.el8.src.rpm
 Repo         : AppStream
 Summary      : Desktop tool for managing virtual machines via libvirt
 URL          : https://virt-manager.org/
 License      : GPLv2+
 Description  : Virtual Machine Manager provides a graphical tool for administering virtual
              : machines for KVM, Xen, and LXC. Start, stop, add or remove virtual devices,
              : connect to a graphical or serial console, and see resource usage statistics
              : for existing VMs on local or remote machines. Uses libvirt as the backend
              : management API.

zintis@c8host ~$ ^C
zintis@c8host ~$ sudo dnf upgrade qemu-kvm qemu-img virt-manager libvirt libvirt-python
CentOS-8 - AppStream                                                                            2.1 kB/s | 4.3 kB     00:02    
CentOS-8 - Base                                                                                 1.7 kB/s | 3.9 kB     00:02    
CentOS-8 - Extras                                                                               687  B/s | 1.5 kB     00:02    
Adobe Systems Incorporated                                                                      2.6 kB/s | 2.9 kB     00:01    
Package virt-manager available, but not installed.
No match for argument: virt-manager
Package libvirt available, but not installed.
No match for argument: libvirt
No match for argument: libvirt-python
Dependencies resolved.
Nothing to do.
Complete!
zintis@c8host ~$ 

10 YUM files:

echo "exclude=firefox" >> /etc/dnf/dnf.conf

see centos.org wiki for details on repositories.

/etc/dnf/dnf.conf /etc/dnf/dnf.repos.d

/etc/yum.conf (is actually a symlink to /etc/dnf/dnf.conf)

11 How DNF differs from YUM

This taken right out of opensource.com:

CLI commands that differ in DNF and yum Following are some of the changes to yum's command-line interface (CLI) you will find in DNF.

  • dnf update or dnf upgrade: Executing either dnf update or dnf upgrade has the

same effect in the system: both update installed packages. However, dnf upgrade is preferred since it works exactly like yum –obsoletes update.

  • resolvedep: This command doesn't exist in DNF. Instead, execute dnf provides

to find out which package provides a particular file.

  • deplist: Yum's deplist command, which lists RPM dependencies, was removed in

DNF because it uses the package-dependency solver algorithm to solve the dependency query.

  • dnf remove <package>: You must specify concrete versions of whatever you want

to remove. For example, dnf remove kernel will delete all packages called "kernel," so make sure to use something like dnf remove kernel-4.16.x.

  • dnf history rollback: This check, which undoes transactions after the one you

specifiy, was dropped since not all the possible changes in the RPM Database Tool are stored in the history of the transaction.

  • --skip-broken: This install command, which checks packages for dependency

problems, is triggered in yum with --skip-broken. However, now it is part of dnf update by default, so there is no longer any need for it.

Note: --skip-broken is the same as rpm -i --nodep

  • -b, –best: These switches select the best available package versions in

transactions. During dnf upgrade, which by default skips over updates that cannot be installed for dependency reasons, this switch forces DNF to consider only the latest packages. Use dnf upgrade –best.

  • –allowerasing: Allows erasing of installed packages to resolve

dependencies. This option could be used as an alternative to the yum swap X Y command, in which the packages to remove are not explicitly defined.

For example: dnf –allowerasing install Y.

  • –enableplugin: This switch is not recognized and has been dropped.

DNF Automatic The DNF Automatic tool is an alternative CLI to dnf upgrade. It can execute automatically and regularly from systemd timers, cron jobs, etc. for auto-notification, downloads, or updates.

To start, install dnf-automatic rpm and enable the systemd timer unit (dnf-automatic.timer). It behaves as specified by the default configuration file (which is /etc/dnf/automatic.conf).

#yum install dnf-automatic #systemctl enable dnf-automatic.timer #systemctl start dnf-automatic.timer #systemctl status dnf-automatic.timer dnf-automatic-timer.png Result of # systemctl enable dnf-automatic.timer Other timer units that override the default configuration are listed below. Select the one that meets your system requirements.

dnf-automatic-notifyonly.timer: Notifies the available updates dnf-automatic-download.timer: Downloads packages, but doesn't install them dnf-automatic-install.timer: Downloads and installs updates Basic DNF commands useful for package management #yum install dnf: This installs DNF RPM from the yum package manager.

yum-install-dnf.png Output of # yum install dnf

dnf-version.png Output of # dnf –version

dnf-list-kernel.png Output of # dnf list kernel command

dnf-check-update.png Output of # dnf check-update kernel

dnf-search.png Output of # dnf search

dnf-repolist.png Output of # dnf repolist all

dnf-list-recent.png Output of # dnf list –recent

dnf-updateinfo-list-available-sec.png OUtput of # dnf updateinfo list available sec

dnfupdateinfo-severity-critical.png Output of # dnf updateinfo list available sec –sec-severity Critical

dnf-updateinfo-fedora.png Output of # dnf updateinfo FEDORA

dnf-upgrade-security.png Output of # dnf upgrade –security Summary These are just a small number of DNF's features, changes, and commands. For complete information about DNF's CLI, new plugins, and hook APIs, refer to the DNF guide.

12 add these to proper .org file:

systemctl list-units –type target –all

dnf grouplist -v –hidden

12.1 Home

13 apt and apt-get for Non-RH systems

Another very common package manager is apt and apt-get used on Debian based distros, such as Kali Linux.

13.1 apt repositories (a.k.a. sources)

apt calls them sources and keeps a list of which "sources" to search for packages in the file: /etc/apt/sources.list See also /etc/apt/sources.list.d

13.2 apt config file /etc/apt/apt.conf

The config file is in /etc/apt/apt.conf. see also /etc/apt/apt.conf.d directory for config fragments.

13.3 remove a package:

  • sudo dpkg --remove nmap or sudo apt-get remove nmap

13.4 add a package:

  • sudo apt-get install figlet

14 Difference between apt and apt-get

apt apt-get
   
Newer version command to act as Older version command to act
a front-end for APT as a front end for APT
More user friendly and No progress bar, less user friendly
has a progress bar as compared to “apt” command
   
Has limited functionality Has more functionality, and it’s used
  with bash-scripts more than apt because
  of guaranteed backward compatibility

After that the newer “apt update” command has the following 2 more lines

The “update” command is usually followed by the “upgrade” command (in most but not all cases).

In the “apt” command the “update” sub-command does the job of “Building dependency tree” while in the “apt-get” command this job is given to the “upgrade” sub-command.

15 Alma Linux Repos

From https://wiki.almalinux.org/repos/AlmaLinux.html the available repos are:

Repository Enabled on Alma v8 Enabled Alma v9
     
BaseOS Default Default
AppStream Default Default
Extras Default Default
PowerTools/CRB dnf config-manager dnf config-manager
  –set-enabled powertools –set-enabled crb
High Availability dnf config-manager dnf config-manager
  –set-enabled ha –set-enabled ha
EPEL dnf install epel-release dnf install epel-release
     

15.1 Alma linux repository contents

Content in the BaseOS repository is intended to provide a core set of the underlying OS functionality that provides the foundation for all installations.

Content in the AppStream repository includes additional user space applications, runtime languages, and databases in support of the varied workloads and use cases.

Content in the extras repository includes packages that are not available in RHEL. They are mostly release packages for additional repos like EPEL, ELRepo or the various CentOS SIGs.

The PowerTools repository contains additional packages for use by developers. This repository is also known as the "CodeReady Builder" repository used on RHEL

The High Availability add-on provides on-demand failover services between nodes within a cluster

The epel release is extra packages for enterpriese linux Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux.

15.2 Fixing conflict in CentOS8 and Alma Linux ImageMagic

On vm1 and vm5 I had to remove ImageMagic before I could successfully dnf update the newly installed Alma Linux (from CentOS transition).

sudo dnf remove ImageMagick-libs.x86_64 

My dnf output looked like:

sudo dnf remove ImageMagick-libs.x86_64 
Dependencies resolved.
==================================================================================================================================
 Package                            Architecture             Version                           Repository                    Size
==================================================================================================================================
Removing:
 ImageMagick-libs                   x86_64                   6.9.10.86-1.el8                   @epel                        8.4 M
Removing unused dependencies:
 fftw-libs-double                   x86_64                   3.3.5-11.el8                      @AppStream                   3.0 M

Transaction Summary
==================================================================================================================================
Remove  2 Packages

And my dnf list before I removed ImageMagick looked like this:

sudo dnf list | grep -i imagemagic
ImageMagick-libs.x86_64                                           6.9.10.86-1.el8                                            @epel                
ImageMagick6-libs.x86_64                                          1:6.9.12.40-1.el8.remi                                     @remi-safe           
ImageMagick.x86_64                                                6.9.12.77-1.el8                                            epel                 
ImageMagick-c++.x86_64                                            6.9.12.77-1.el8                                            epel                 
ImageMagick-c++-devel.x86_64                                      6.9.12.77-1.el8                                            epel                 
ImageMagick-devel.x86_64                                          6.9.12.77-1.el8                                            epel                 
ImageMagick-djvu.x86_64                                           6.9.12.77-1.el8                                            epel                 
ImageMagick-doc.x86_64                                            6.9.12.77-1.el8                                            epel                 
ImageMagick-libs.x86_64                                           6.9.12.77-1.el8                                            epel                 
ImageMagick-perl.x86_64                                           6.9.12.77-1.el8                                            epel                 
ImageMagick7-c++.x86_64                                           1:7.1.1.5-1.el8.remi                                       remi-safe            
ImageMagick7-djvu.x86_64                                          1:7.1.1.5-1.el8.remi                                       remi-safe            
ImageMagick7-heic.x86_64                                          1:7.1.1.5-1.el8.remi                                       remi-safe            
ImageMagick7-libs.x86_64                                          1:7.1.1.5-1.el8.remi                                       remi-safe            
zintis@vm5~[1003] $