Package Management using Dandified YUM (DNF)

You are currently viewing Package Management using Dandified YUM (DNF)
  • YUM is the package manager in RHEL 6 (and based distributions) and earlier versions of RHEL, while DNF is the package manager used in RHEL 7 and later . The main difference between the two is that DNF has much better performance and uses the libsolv library to resolve dependencies. Additionally, DNF allows for more granular control with regards to package updates and can be used to install specific versions of packages.

  • DaNdiFied YUM or DNF in short, is a rewrite of YUM itself, and has recently replaced YUM as the default package manager in rpm based distributions like Fedora, Red Hat Enterprise Linux, CentOS, Rocky Linux, Alma Linux etc.

  • YUM, previously default package manager, stands for Yellowdog Updater, Modified is also a rewrite of (YUP) Yellowdog UPdater, a software updater for Yellow Dog Linux (now-defunct Linux distribution).

  • Infact, currently both /usr/bin/yum and /usr/bin/dnf are symbolic links pointing to the same python executable script /usr/bin/dnf-3 as very much evident from the image below, so basically yum is just an alias to dnf on current prevailing systems based on version RHEL 7 and later.

    YUMnDNF

  • The main configuration file for YUM is /etc/yum.conf and DNF is /etc/dnf/dnf.conf and by
    default both are exactly identical.
    # diff –s /etc/yum.conf /etc/dnf/dnf.conf (for verfifying files are identical or not)

  • YUM/DNF command searches one or numerous configured and enabled repositories for pkgs and their dependencies so they may be installed together in an effort to alleviate dependency issues.

  • The repositories configuration files (with extension .repo) are by default located within /etc/yum.repos.d directory.

  • A YUM/DNF repository configuration file include following keys at minimum:

    1. a repo id in square brackets
    2. a repo name and
    3. a url called baseurl pointing to repository location (which may be either local or remote).
  • If the baseurl is pasted in a browser, the contents should display the RPM packages, possibly in one or more subdirectories and a repodata directory with information about available packages.

  • Repo Config File sample: /etc/yum.repos.d/localPkgs.repo

    [localPkgs]
    name=Rocky Linux $releasever - local AppStream and BaseOS
    enabled=1
    gpgcheck=1
    baseurl=file:///var/ftp/pub/local
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
    

    Note: Few important points about above repo file:
    1. enabled key default value is True i.e. 1
    2. gpgcheck key default value is False i.e. 0
    3. Last directory in baseurl path must be the one containing directory "repodata"
    4. gpgkey key is required only when gpgcheck=1

  • Minimal Repo Config File sample (minimizing above repo file):

    [localPkgs]
    name=Rocky Linux $releasever - local AppStream and BaseOS
    baseurl=file:///var/ftp/pub/local
    
  • Commands listed below can either start with yum or dnf keyword, both will work, because both are symbolic links to python executable file dnf-3, though dnf-3 can also be used directly

  • Information Gathering Commands:

    # dnf --version
    For determining installed version of DNF/YUM and RPM

    # dnf repolist
    List repo id(s) and repo name(s) of enabled repositories

    # dnf repolist all
    List repo id(s) and repo name(s) of all (enabled & disabled) repositories

    # dnf list (OR list all)
    List all packages of enabled repositories (both Available & Installed)

    # dnf list available [| wc -l]
    # dnf list installed [| wc -l]
    # dnf list updates [| wc -l]
    # dnf list httpd
    # dnf list “http*”
    # dnf list “*noarch”
    # dnf list installed | grep “.noarch” | wc -l
    # dnf list available | grep “.ynoarch” | wc -l

    # dnf list kernel
    List all installed and available kernels as per the configured and enabled repositories

    # uname –r
    For listing currently running kernel version and release

    # uname –a
    For listing kernel info and additional system information

    # dnf search “web server”
    Search within Name & Summary fields

    # dnf search all “web server”
    Search within Name, Summary and Description fields

    # dnf info nginx
    Gives detailed information about package “nginx” like name, summary, description, disk space needed for installation, repository info etc.

    # dnf provides PATHNAME
    # dnf provides /usr/sbin/useradd (File)
    # dnf provides /usr/bin/passwd (File)
    # dnf provides /var/ftp/pub (Directory)
    # dnf provides [/, /root, /home, /etc,…]

  • Install Commands:
    Note: Packages are normally digitally signed to ensure they are legitimate. If the package is not signed by a key trusted by your system, it will be rejected while installation. Therefore, the --nogpgcheck option can be used to disable the signature check if you are certain the package is legitimate. Though --nogpgcheck is not required, if a package is installed with dnf localinstall.

    # dnf install PACKAGENAME
    Installs the package, if found in enabled repositories

    # dnf install PACKAGENAME --nogpgcheck
    Installs the package, without verifying gpg signature.

    # dnf localinstall PACKAGEFILE.rpm
    Installs package(s) directly, lying on the local filesystem. It automatically downloads any dependencies the package has from any configured and enabled yum repositories.

  • Update Commands:

    # dnf list updates (OR # dnf check-update)
    For listing all the updates available for the system

    # dnf update
    For installing all relevant updates

    # dnf update PACKAGENAME
    For updating specific package

    # dnf update(OR install) kernel
    DNF always installs a new kernel regardless of whether you are using update or install option.

    Caution: When using rpm command:
    # rpm -ivh kernel, installs new kernel (Recommended), whereas
    # rpm -Uvh kernel, replaces the current kernel with new one (Not recommended)

    Note: Since a kernel can only be tested by booting to the kernel, the package is specifically designed so that multiple versions may be installed at once. If the new kernel fails to boot, the old kernel is still available. The configuration files hold a list of pkgs to “always install” (includes kernel by default) even if the admin requests an update.

  • Remove Commands:

    # dnf remove PACKAGENAME
    Removes an installed package PACKAGENAME, along with:
    Dependant packages i.e. packages dependent on PACKAGENAME and
    Unsused dependencies i.e. packages which got installed as dependencies while installing PACKAGENAME

    TryThisExperiment:
    # dnf install nginx
    # dnf remove nginx-all-modules (OR # dnf remove nginx)

  • DNF/YUM Group Commands:

    1. Packages Groups are collection of related software packages installed together for a particular purpose. There are two types of groups:
      1. Regular Groups: collections of packages.
      2. Environment Groups: collections of regular groups which include their own packages.
    2. Packages or groups provided by a group may be:
      1. Mandatory: must be installed if the group is installed
      2. Default: normally installed if the group is installed, unless stated otherwise.
      3. Optional: are not installed when the group is, unless asked for specifically.
      4. Conditional

    # dnf group
    List how many regular (not environment groups) groups are installed and available.

    # dnf grouplist (OR # dnf group list)
    List names of all installed and available groups

    # dnf grouplist ids
    Output is same as above command, with additional group ids information.
    Note: Groups can be installed, updated, removed, and otherwise queried by either name or ID

    # dnf grouplist installed (OR # dnf grouplist installed ids)
    # dnf grouplist available (OR # dnf grouplist available ids)

    # dnf grouplist hidden (OR # dnf grouplist hidden ids)
    List hidden groups (the groups installed through environment groups are usually hidden by default)

    # dnf groupinfo GROUP (OR # dnf group info GROUP)
    List mandatory, default, and optional packages of GROUP
    For Example:
    # dnf groupinfo “Internet Browser” (Contains Mandatory and Optional Packages)
    # dnf groupinfo “Mail Server” (Contains Default and Optional Packages)
    # dnf groupinfo “Infiniband Support” (Contains all Mandatory, Default, Optional and Conditional Packages)
    # dnf groupinfo "Remote Desktop Clients" (Contains only Optional Packages)

    # dnf groupinstall GROUP (OR # dnf group install GROUP)
    Install a group which will install its mandatory and default packages (or groups) and the packages they depend on.
    For Example:
    # dnf groupinstall “Infiniband Support”
    Note: If some packages from Mandatory and Default sections are not getting installed, then they are probabaly already installed.
    # dnf groupinstall “Backup Client”
    # dnf groupinstall “Remote Desktop Clients” -y
    Note: Here above none of the packages will be installed because of no Mandatory and Default G Group of packages.

    # dnf groupupdate GROUP (OR # dnf group update GROUP)
    # dnf groupremove GROUP (OR # dnf group remove GROUP)

  • Dry/Test Run Commands:
    Running a dry run (or test run), will not make any changes to the system (i.e. no installaion, removal or updating of packages will happen). It will return an exit code 0, if everything goes smoothly, otherwise a non-zero value will be returned implying failure. Good for scripting.
    For Example:
    # dnf -y groupinstall --setopt tsflags=test "Backup Client"
    # dnf -y install --setopt tsflags=test nginx
    # dnf -y remove --setopt tsflags=test nginx

    # dnf install nginx --assumeno (INCORRECT DRY RUN)
    Note: One may choose to use above command as dry run, but this isn’t correct. It will list the packages to be installed, uninstalled and updated but will end with a non-zero exit code all the time i.e. after listing packages, the operation will be aborted.

  • History/Log commands:

    # tail /var/log/dnf.log
    All install and remove transactions are logged in /var/log/dnf.log

    # dnf history
    Show a summary of install and remove transactions

    # dnf history undo NUMBER
    A transaction can be reversed using undo

    # dnf history redo NUMBER
    A transaction can be repeated using redo

    # dnf history info NUMBER
    Describe the listed transaction number, if no number mentioned, then describes the latest transaction.

  • Repository Commands (for enabling/disabling repositories):

    # createrepo -v /path/to/dir/with/RPMs
    Note: Install package createrepo_c to get createrepo command (# yum install createrepo_c) It will create repodata directory in current working directory. baseurl field of repo file within /etc/yum.repos.d directory will point to this directory.
    repodata directory contains files holding metadata about RPMs

    # createrepo --update /path/to/dir/with/RPMs
    Required, If repository metadata is already created and if new RPMs are added afterwards

    # dnf install gnuplot --enablerepo appstream, baseos
    Temporarily enabling repositories on the fly

    # dnf install gnuplot --disablerepo appstream, baseos
    Temporarily disabling repositories on the fly

    # dnf list httpd* --disablerepo "*" --enablerepo "local*"
    Selecting only repositories with repo id starting with keyword "local" (Using only local repositories from all enabled repositories)

    # yum-config-manager --disable baseos OR
    # dnf config-manager --set-disabled baseos
    Permanently disabling repositories
    Note: Install package yum-utils to get yum-config-manager command (# yum install yum-utils)

    # yum-config-manager --enable appstream,baseos OR
    # dnf config-manager --set-enabled appstream,baseos
    Permanently enabling repositories

  • Enabling Third-Party Repositories (epel, rpmfusion, etc…):
    Note: Here I’ll be explaining thing as per the Linux distribution Rocky Linux, which I personally use.

    Enabling EPEL Repository:

    1. Enable extras Repo, which comes configured with the distribution. In Rocky Linux, enable extras repo configured using file Rocky-Extras.repo file.
      # yum-config-manager --enable extras (enabling)

    2. After enabling and syncing, search for keyword "epel" and "rpmfusion"
      # yum list (syncing)
      # yum search all "epel" (searching)
      # yum install epel-release (installing)

      yum search all "epel" OUTPUT

      Message asking for Enabling CRB Repository

    3. If you get the message shown above asking for enabling CRB repository, do the following:
      # yum-config-manager --enable powertools
      # crb help
      # crb status (For finding status of CRB repo i.e. CodeReady Builder repo)
      Note:

      • crb repo is same as powertools repo, clear from the screen clipping below.
        CRB Status
      • After installing epel-release package, epel-next-release also becomes available, which can also be further installed and enabled.
      • For more information visit Fedora EPEL

    Enabling RPMFusion Repository:
    Note: After enabling EPEL repository, you may move on to enabling RPMFusion Repository.

    # yum search all "rpmfusion"
    # yum install rpmfusion-free-release

    Note:

    1. Once rpmfusion-free-release is installed and enabled, other rpmfusion repositories like rpmfusion-free-release-tainted can also be installed and enabled.
    2. For installing rpmfusion-nonfree-release and rpmfusion-nonfree-release-tainted repos, visit link RPMFusion Configuration
    3. free and nonfree repositories.
      • free for Open Source Software (as defined by the Fedora Licensing Guidelines) which the Fedora project cannot ship due to other reasons.
      • nonfree for redistributable software that is not Open Source Software (as defined by the Fedora Licensing Guidelines); this includes software with publicly available source-code that has "no commercial use"-like restrictions.
    4. There are other third party repositories and they can be searched using a search engine.

Leave a Reply