Introduction

Yellowdog Updater, Modifier (YUM) is a package manager, which is widely used to manage rpm packages in Red Hat based distributions. Unlike rpm command line tool, it can automatically resolve, download and install package dependencies.

As yum is also installed as an RPM package, we can query details about this like any other RPM package. I am using CentOS 7 for running examples in this article.

$ cat /etc/centos-releas
CentOS Linux release 7.5.1804 (Core)

For showing version of yum package we can run following command.

$ rpm -q yum
yum-3.4.3-158.el7.centos.noarch

The examples in this article are taken disabling fastestmirror plugin. To disable fastestmirror plugin change enabled=1 to enabled=0 in /etc/yum/pluginconf.d/fastestmirror.conf file.

Finding Package

yum has very comprehensive commands for finding packages. We can list various packages using list subcommand. By default list subcommand shows installed and available packages.

$ yum list

Installed Packages
GeoIP.x86_64                          1.5.0-11.el7                     @anaconda
NetworkManager.x86_64                 1:1.10.2-13.el7                  @anaconda
NetworkManager-libnm.x86_64           1:1.10.2-13.el7                  @anaconda
NetworkManager-team.x86_64            1:1.10.2-13.el7                  @anaconda
# ... (Skipping lines until available section)
Available Packages
389-ds-base.x86_64                    1.3.8.4-25.1.el7_6               updates
389-ds-base-devel.x86_64              1.3.8.4-25.1.el7_6               updates
389-ds-base-libs.x86_64               1.3.8.4-25.1.el7_6               updates
389-ds-base-snmp.x86_64               1.3.8.4-25.1.el7_6               updates

# ... (Skipping further output)

Each line contains package description in following format:

PackageName     [Epoch:]PackageVersion    SourceRepositoryName

If Epoch number exists it is used to override regular version numbering. If no Epoch number than its default to 1. If two packages exists with following version 1.3.4 and 2:1.2.0, later will get precedence while installing although former is updated version.

Last column is the source repository of package. Here repository name @anaconda means those packages were installed from installation media.

We can list only installed, available packages using installed, avaibale list option respectively.

$ yum list installed

Installed Packages
GeoIP.x86_64                          1.5.0-11.el7                     @anaconda
NetworkManager.x86_64                 1:1.10.2-13.el7                  @anaconda
NetworkManager-libnm.x86_64           1:1.10.2-13.el7                  @anaconda
NetworkManager-team.x86_64            1:1.10.2-13.el7                  @anaconda

# ... (Showing first 5 lines)

list subcommand also supports updates for listing updates of installed packages, extras for listing packages which are installed in system but doesn’t contain in any repository, obsoletes for listing installed packages which are replaced by other packages.

We can further filter list by specifying package name glob. For listing all package names starting with ‘vim’:

$ yum list all vim* # Same as 'yum list vim*'

vim-minimal.x86_64                  2:7.4.160-4.el7                 @anaconda
Available Packages
vim-X11.x86_64                      2:7.4.160-6.el7_6               updates
vim-common.x86_64                   2:7.4.160-6.el7_6               updates
vim-enhanced.x86_64                 2:7.4.160-6.el7_6               updates
vim-filesystem.x86_64               2:7.4.160-6.el7_6               updates
vim-minimal.x86_64                  2:7.4.160-6.el7_6               updates

By default yum only lists the latest package, we can provide –showduplicates options for listing all packages.

$ yum list python

Installed Packages
python.x86_64                           2.7.5-68.el7                    @anaconda
Available Packages
python.x86_64                           2.7.5-80.el7_6                  updates

$ yum --showduplicates list python

Installed Packages
python.x86_64                           2.7.5-68.el7                    @anaconda
Available Packages
python.x86_64                           2.7.5-76.el7                    base
python.x86_64                           2.7.5-77.el7_6                  updates
python.x86_64                           2.7.5-80.el7_6                  updates

We can also query detailed information using info subcommand. info subcommand also takes installed, available, obsoletes options like list.

$ yum info tree

Available Packages
Name        : tree
Arch        : x86_64
Version     : 1.6.0
Release     : 10.el7
Size        : 46 k
Repo        : base/7/x86_64
Summary     : File system tree viewer
URL         : http://mama.indstate.edu/users/ice/tree/
License     : GPLv2+
Description : The tree utility recursively displays the contents of directories in a
            : tree-like format.  Tree is basically a UNIX port of the DOS tree
            : utility.

We can also search in package name and summary using using search subcommand.

$ yum search vim

protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor

For searching also in metadata we can add all option.

$ yum search all vim

vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
grilo-plugins.x86_64 : Plugins for the Grilo framework

If we don’t know the package name but want to query by executable or file name, yum has provides subcommand for that. For querying which package provides /etc/passwd file we can execute following command.

$ yum provides /etc/passwd

setup-2.8.71-10.el7.noarch : A set of system configuration and setup files
Repo        : base
Matched from:
Filename    : /etc/passwd


setup-2.8.71-9.el7.noarch : A set of system configuration and setup files
Repo        : @anaconda
Matched from:
Filename    : /etc/passwd

For investigating dependencies of package yum have deplist command. Following line will show dependencies of tree command.

$ yum deplist tree

package: tree.x86_64 1.6.0-10.el7
  dependency: libc.so.6(GLIBC_2.14)(64bit)
   provider: glibc.x86_64 2.17-260.el7_6.6
  dependency: rtld(GNU_HASH)
   provider: glibc.x86_64 2.17-260.el7_6.6
   provider: glibc.i686 2.17-260.el7_6.6

Installing Package

yum install subcommand is used for installing new packages. Unlike rpm, this command will also download and install dependencies.

$ sudo yum install tree

Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================
 Package       Arch              Version                  Repository          Size
======================================================================================
Installing:
 tree         x86_64            1.6.0-10.el7                base              46 k

Transaction Summary
======================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]:

As tree doesn’t have any external package dependencies, only 1 package, tree itself will be installed. We can see that yum is prompting us for y/d/N option. y will install the package. We can also provide -y flag with install command for skipping confirmation. If we press N, installation will be aborted and a transaction file will be created.

Is this ok [y/d/N]: N
Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2019-08-14.17-34.zxALJW.yumtx

Let’s see the content of /tmp/yum_save_tx.2019-08-14.17-34.zxALJW.yumtx file.

$ sudo cat/tmp/yum_save_tx.2019-08-14.17-34.zxALJW.yumtx

298:e4fd91afa5eacab19b081c18b730515b7a7353cc
0
1
installed:299:cbe54d850072ab2b5f5cf9bbb03d2e7d23a167b4
1
mbr: tree,x86_64,0,1.6.0,10.el7 70
  repo: base
  ts_state: u
  output_state: 20
  isDep: False
  reason: user
  reinstall: False

We can continue the transaction using following command:

$ sudo yum load-transaction /tmp/yum_save_tx.2019-08-14.17-34.zxALJW.yumtx

If we select d in installation prompt, then the package won’t be install but will be downloaded in /var/cache/yum directory.

Is this ok [y/d/N]: d
Background downloading packages, then exiting:
tree-1.6.0-10.el7.x86_64.rpm                                      |  46 kB  00:00:00
exiting because "Download Only" specified

We can search the downloaded file using find command like below:

$ find /var/cache/yum -name tree*
/var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm

We can directly download a package using –downloadonly flag. With –downloaddir we can specify download location.

$ sudo yum install --downloadonly --downloaddir=$PWD tree
# Omitting output

$ ls
tree-1.6.0-10.el7.x86_64.rpm

We can install .rpm packages using yum localinstall command. Unlike rpm command installing with localinstall also downloads and installs dependencies.

$ sudo yum localinstall tree-1.6.0-10.el7.x86_64.rpm

Sometime a packge may need to reinstall. yum has reinstall command for that.

$ sudo yum reinstall tree

Updating Package

We can check for update using following command. This command will download new meatadata and display list like yum list updates.

$ sudo yum check-update

We can specify pacakge glob then packges matching that will be printed. Let’s check the update status of curl packge.

$ sudo yum check-update curl
curl.x86_64                   7.29.0-51.el7_6.3                    updates

$ rpm -q curl
curl-7.29.0-46.el7.x86_64

We can update a package using update subcommand. If don’t specify any packges all updatable packges will be updated. We can add –skip-broken flag for skipping packages with unmet dependcies. We can also skip update of packges using -x flag.

$ sudo yum update curl

# Update all installed updatable packages except vim
$ sudo yum update --skip-broken -x vim

By default yum update installs obsoletes packages. If update of obsolete packages is disabled in /etc/yum.conf, then we can update obsoletes packages using –obsoletes flag with update or using upgrage subcommand.

Obsolete packages are those installed packages which are replaced by other packages. We can list obsolete packages using following command.

$ yum list obsoletes

Obsoleting Packages
grub2.x86_64                        1:2.02-0.76.el7.centos.1           updates
    grub2.x86_64                    1:2.02-0.65.el7.centos.2           @anaconda
grub2-tools.x86_64                  1:2.02-0.76.el7.centos.1           updates
    grub2-tools.x86_64              1:2.02-0.65.el7.centos.2           @anaconda
grub2-tools-extra.x86_64            1:2.02-0.76.el7.centos.1           updates
    grub2-tools.x86_64              1:2.02-0.65.el7.centos.2           @anaconda
grub2-tools-minimal.x86_64          1:2.02-0.76.el7.centos.1           updates
    grub2-tools.x86_64              1:2.02-0.65.el7.centos.2           @anaconda

All of these are grub2 related packages. We can upgrade those packages using command below:

$ sudo yum upgrade grub2*

Removing Package

Package can be removed using remove command. This command doesn’t remove dependencies. For removing package with all it’s unused dependencies autoremove can be used.

$ sudo yum autoremove -y tree

Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be erased
--> Finished Dependency Resolution
--> Finding unneeded leftover dependencies
Found and removing 0 unneeded dependencies

Dependencies Resolved

================================================================================
 Package        Arch             Version                  Repository       Size
================================================================================
Removing:
 tree           x86_64           1.6.0-10.el7             @base            87 k

Transaction Summary
================================================================================
Remove  1 Package

Installed size: 87 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : tree-1.6.0-10.el7.x86_64                                     1/1
  Verifying  : tree-1.6.0-10.el7.x86_64                                     1/1

Removed:
  tree.x86_64 0:1.6.0-10.el7

Complete!

Yum Group

We can install multiple packages which are usually installed together using group. yum has a group subcommand.

We can list groups using list command. ids options also prints group id.

$ yum group list ids

Available Environment Groups:
   Minimal Install (minimal)
   Compute Node (compute-node-environment)
   Infrastructure Server (infrastructure-server-environment)
   File and Print Server (file-print-server-environment)
   Basic Web Server (web-server-environment)
   Virtualization Host (virtualization-host-environment)
   Server with GUI (graphical-server-environment)
   GNOME Desktop (gnome-desktop-environment)
   KDE Plasma Workspaces (kde-desktop-environment)
   Development and Creative Workstation (developer-workstation-environment)
Available Groups:
   Compatibility Libraries (compat-libraries)
   Console Internet Tools (console-internet)
   Development Tools (development)
   Graphical Administration Tools (graphical-admin-tools)
   Legacy UNIX Compatibility (legacy-unix)
   Scientific Support (scientific)
   Security Tools (security-tools)
   Smart Card Support (smart-card)
   System Administration Tools (system-admin-tools)
   System Management (system-management)

Adding hidden will also show groups not marked as visible. Group list also take options like installed, environment, available.

We can query information using info command. We can either use group name or id.

$ yum group info "Smart Card Support"
# Or
$ yum group info smart-card

Group: Smart Card Support
 Group-Id: smart-card
 Description: Support for using smart card authentication.
 Default Packages:
   +coolkey
   +esc
   +pcsc-lite-ccid
 Optional Packages:
   opencryptoki
   opensc

Note coolkey package had + before it, means it will be installed if we install the group. = means package is already installed as a part of group and empty means package is installed but not as part of group.

group install command is used for installing groups.

$ sudo yum group install <groupNameOrId>

We can also use package install command to install group. We just need to add @ before group name. For installing smart-card group. We have to write.

$ sudo yum install @smart-card

# Or
$ sudo yum install @"Smart Card Support"

Group can have 3 type of package Mandaotry, Default, Optional. By default only Mandatory and Default packages are installed. We can add group-package-type option in /etc/yum.conf or add with –setopt while installing package.

$ sudo yum --setopt=group-package-type=mandatory,default,optional \
           group install smart-card

Is it possible to install a package separately and then install the group containing that package. We may want to treat that package as part of that group. For that we have to run following commands:

$ sudo yum group mark install <groupNameOrId>
$ sudo yum group mark convert <groupNameOrId>

We can update group using update command:

$ sudo yum update @smart-card
$ sudo yum update @"Smart Card Support"

# Or
$ sudo yum group update smart-card

For removing we have group remove but nothing like autoremove. For auto removing we have to use package level command.

$ sudo yum remove @smart-card
$ sudo yum remove @"Smart Card Support"

# Or
$ sudo yum group remove smart-card
$ sudo yum group remove "Smart Card Support"

# Or better `autoremove`
$ sudo yum autoremove @smart-card

Configuration

yum main configuration file is /etc/yum.conf. Also has a directory /etc/yum/ which contains various other configuration files.

Plugin related configurations are located in /etc/yum/pluginconf.d/ directory. Files ending with .repo files in /etc/yum.repos.d directory contain repository information. Each file can contain multiple repository definition.

These repository files are installed as part of centos-release package. We can see enabled repository using following command. disabled shows all disabled repository.

$ yum repolist enabled # Or yum repolist

repo id                          repo name                          status
base/7/x86_64                    CentOS-7 - Base                    10,019
extras/7/x86_64                  CentOS-7 - Extras                     435
updates/7/x86_64                 CentOS-7 - Updates                  2,500
repolist: 12,954

Detailed repository information can be seen using repoinfo command. For querying detailed information about base repository we have to write

$ yum repoinfo base

Repo-id      : base/7/x86_64
Repo-name    : CentOS-7 - Base
Repo-status  : enabled
Repo-revision: 1543161601
Repo-updated : Sun Nov 25 22:00:34 2018
Repo-pkgs    : 10,019
Repo-size    : 9.4 G
Repo-mirrors : http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock
Repo-baseurl : http://mirror.dhakacom.com/centos/7.6.1810/os/x86_64/ (9 more)
Repo-expire  : 21,600 second(s) (last: Wed Aug 14 17:05:26 2019)
  Filter     : read-only:present
Repo-filename: /etc/yum.repos.d/CentOS-Base.repo

repolist: 10,019

We can temporarily disable a repository using –disablerepo and enable a disabled repository using –enablerepo flag.

We can see that /etc/yum.repos.d/CentOS-Base.repo has base, extra, updates, centosplus repository definition. By default centosplus repository is disabled. We can update that file or enable temporarily for a single command like below:

$ yum --disablerepo="*" --enablerepo="centosplus" list

Tools Version

  • yum 3.4.3-158.el7.centos.noarch

Bookmarks