CompTIA Linux+ Certification Guide
上QQ阅读APP看书,第一时间看更新

YUM

Yellowdog Updater, Modified, is commonly known as YUM. YUM is an open source command-line method for package management for systems using a Red Hat distribution. As Linux administrators, YUM enables us to perform automatic updates and package and dependency management on RPM-based distributions. YUM is similar in nature to its Debian counterpart, APT. The YUM utility makes use of various software repositories.

A software repo, as it is commonly called, stores a variety of packages. One of the main reasons for using YUM is that it detects whether any dependency files are needed for a particular package. It then prompts the user of the needed files and offers to install them as part of the package installation, which the user should have initiated from the get-go.

An interesting point to note is the fact that YUM works with RPM packages.

To begin with, we can view the available packages in the YUM database by using the list option:

[philip@localhost ~]$ yum list | less
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
* base: centos.mirror.iweb.ca
* extras: centos.mirror.iweb.ca
* updates: centos.mirror.iweb.ca
Installed Packages
GConf2.x86_64 3.2.6-8.el7 @anaconda
GeoIP.x86_64 1.5.0-11.el7 @anaconda
ModemManager.x86_64 1.6.0-2.el7 @anaconda
ModemManager-glib.x86_64 1.6.0-2.el7 @anaconda
NetworkManager.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-adsl.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-glib.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-libnm.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-libreswan.x86_64 1.2.4-2.el7 @anaconda
NetworkManager-libreswan-gnome.x86_64 1.2.4-2.el7 @anaconda
NetworkManager-ppp.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-team.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-tui.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-wifi.x86_64 1:1.8.0-9.el7 @anaconda
PackageKit.x86_64 1.1.5-1.el7.centos @anaconda

From the preceding output, the repo data is precisely two-weeks old. This can be solved by running makecache fast with YUM:

[philip@localhost ~]$ yum makecache fast
Loaded plugins: fastestmirror, langpacks
Existing lock /var/tmp/yum-philip-FdEYSO/x86_64/7/yum.pid: another copy is running as pid 2322.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 24 M RSS (415 MB VSZ)
Started: Tue Jul 31 05:49:03 2018 - 00:11 ago
State : Traced/Stopped, pid: 2322
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 24 M RSS (415 MB VSZ)
Started: Tue Jul 31 05:49:03 2018 - 00:13 ago
State : Traced/Stopped, pid: 2322
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 24 M RSS (415 MB VSZ)
Started: Tue Jul 31 05:49:03 2018 - 00:15 ago
State : Traced/Stopped, pid: 2322
^C
Exiting on user cancel.
[philip@localhost ~]$

If you are faced with this message whilst attempting to update the cache, then we can remove the lock file, which will remedy this:

[philip@localhost ~]$ rm /var/tmp/yum-philip-FdEYSO/x86_64/7/yum.pid 
[philip@localhost ~]$ yum makecache fast

Loaded plugins: fastestmirror, langpacks
http://ftp.jaist.ac.jp/pub/Linux/CentOS/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: ftp.jaist.ac.jp; Name or service not known"
Trying other mirror.
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
http://centos.mirror.iweb.ca/7/updates/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: centos.mirror.iweb.ca; Name or service not known"
Trying other mirror.
updates | 3.4 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 172 kB 00:00:10
(2/2): updates/7/x86_64/primary_db | 4.3 MB 00:00:13
Loading mirror speeds from cached hostfile
* base: centos.mirror.iweb.ca
* extras: centos.mirror.iweb.ca
* updates: centos.mirror.iweb.ca
Metadata Cache Created
[philip@localhost ~]$

Awesome job! We can see that the cache has been updated. We can further narrow down the packages being displayed by YUM. To do this, we use the installed option:

[philip@localhost ~]$ yum list installed | less
Loaded plugins: fastestmirror, langpacks
Installed Packages
GConf2.x86_64 3.2.6-8.el7 @anaconda
GeoIP.x86_64 1.5.0-11.el7 @anaconda
ModemManager.x86_64 1.6.0-2.el7 @anaconda
ModemManager-glib.x86_64 1.6.0-2.el7 @anaconda
NetworkManager.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-adsl.x86_641:1.8.0-9.el7 @anaconda
NetworkManager-glib.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-libnm.x86_641:1.8.0-9.el7 @anaconda
NetworkManager-libreswan.x86_64 1.2.4-2.el7 @anaconda
NetworkManager-libreswan-gnome.x86_64 1.2.4-2.el7 @anaconda
NetworkManager-ppp.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-team.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-tui.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-wifi.x86_64 1:1.8.0-9.el7 @anaconda
PackageKit.x86_64 1.1.5-1.el7.centos @anaconda
PackageKit-command-not-found.x86_64 1.1.5-1.el7.centos @anaconda
PackageKit-glib.x86_64 1.1.5-1.el7.centos @anaconda
PackageKit-gstreamer-plugin.x86_64 1.1.5-1.el7.centos @anaconda

From the output, the packages are displayed by package name, package version, and installer. We can also view packages in a group format. For this, we use the grouplist option:

[philip@localhost ~]$ yum grouplist
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: centos.mirror.iweb.ca
* extras: centos.mirror.iweb.ca
* updates: centos.mirror.iweb.ca
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Available Groups:
Compatibility Libraries
Console Internet Tools
Development Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
[philip@localhost ~]$

Great! To view information about a particular package, we can use the info option:

[philip@localhost ~]$ yum info firefox
Installed Packages
Name : firefox
Arch : x86_64
Version : 52.2.0
Release : 2.el7.centos
Size : 149 M
Repo : installed
From repo : anaconda
Summary : Mozilla Firefox Web browser
URL : http://www.mozilla.org/projects/firefox/
License : MPLv1.1 or GPLv2+ or LGPLv2+
Description : Mozilla Firefox is an open-source web browser, designed for standards
: compliance, performance and portability.
Available Packages
Name : firefox
Arch : i686
Version : 60.1.0
Name : firefox
Arch : x86_64
Version : 60.1.0
Description : Mozilla Firefox is an open-source web browser, designed for standards
: compliance, performance and portability.
[philip@localhost ~]$

From the preceding output, there is a lot of useful information pertaining to the package.

We can identify a package for a file by using the provides option:

[philip@localhost ~]$ yum provides /etc/my.cnf
Loaded plugins: fastestmirror, langpacks
1:mariadb-libs-5.5.56-2.el7.i686 : The shared libraries required for MariaDB/MySQL clients
Repo : base
Matched from:
Filename : /etc/my.cnf
1:mariadb-libs-5.5.56-2.el7.x86_64 : The shared libraries required for MariaDB/MySQL clients
Repo : base
Matched from:
Filename : /etc/my.cnf
1:mariadb-libs-5.5.56-2.el7.x86_64 : The shared libraries required for MariaDB/MySQL clients
Repo : @anaconda
Matched from:
Filename : /etc/my.cnf
[philip@localhost ~]$

Based on the output, it is clear that /etc/my.cnf belongs to mariadb-libs-5.5.56-2.el7.x86_64. We can also search for a package by using the search option:

[philip@localhost ~]$ yum search gedit
Loaded plugins: fastestmirror, langpacks
* updates: centos.mirror.iweb.ca
================================================================= N/S matched: gedit =================================================================
gedit-devel.i686 : Support for developing plugins for the gedit text editor
gedit-devel.x86_64 : Support for developing plugins for the gedit text editor
gedit-plugins-data.x86_64 : Common data required by plugins
Name and summary matches only, use "search all" for everything.
[philip@localhost ~]$

Now to update our system, we first use the clean all option:

You need root privilege before doing package maintenance.
[root@localhost philip]# yum clean all
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost philip]#

Next, we use the check-update option:

[root@localhost philip]# yum check-update
Loaded plugins: fastestmirror, langpacks
http://ftp.hosteurope.de/mirror/centos.org/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: ftp.hosteurope.de; Name or service not known"
Trying other mirror.
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:09
(2/4): extras/7/x86_64/primary_db | 172 kB 00:00:08
(3/4): updates/7/x86_64/primary_db | 4.3 MB 00:00:14
(4/4): base/7/x86_64/primary_db | 5.9 MB 00:00:16
Determining fastest mirrors
* base: mirror.us.leaseweb.net
* extras: mirror.us.leaseweb.net
* updates: mirror.us.leaseweb.net
ModemManager.x86_64 1.6.10-1.el7 base accountsservice.x86_64 0.6.45-7.el7 base accountsservice-libs.x86_64 0.6.45-7.el7 base acl.x86_64 2.2.51-14.el7 base attr.x86_64 2.4.46-13.el7 base avahi-gobject.x86_64 0.6.31-19.el7 base avahi-libs.x86_64 0.6.31-19.el7 base yum.noarch 3.4.3-158.el7.centos base yum-plugin-fastestmirror.noarch 1.1.31-45.el7 base yum-utils.noarch 1.1.31-45.el7 base Obsoleting Packages grub2.x86_64 1:2.02-0.65.el7.centos.2 base grub2-tools.x86_64 1:2.02-0.64.el7.centos @anaconda grub2-tools-minimal.x86_64 1:2.02-0.65.el7.centos.2 base
[root@localhost philip]#

Some output has been omitted for brevity. We can also install a package by using the install option:

[root@localhost philip]# yum install talk.x86_64
Loaded plugins: fastestmirror, langpacks
* updates: mirror.us.leaseweb.net
Resolving Dependencies
--> Running transaction check
Dependencies Resolved
=====================================================================
Package Arch Version Repository Size
=====================================================================
Installing:
talk x86_64 0.17-46.el7 base 24 k
Transaction Summary
=====================================================================
Install 1 Package
Total download size: 24 k
Installed size: 31 k
Is this ok [y/d/N]: y
Downloading packages:
talk-0.17-46.el7.x86_64.rpm | 24 kB 00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : talk-0.17-46.el7.x86_64 1/1
Verifying : talk-0.17-46.el7.x86_64 1/1
Installed:
talk.x86_64 0:0.17-46.el7
Complete!
[root@localhost philip]#

Awesome! We can also remove a package in the reverse order. To do this, we use the remove option:

[root@localhost philip]# yum remove talk.x86_64
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package talk.x86_64 0:0.17-46.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================
Package Arch Version Repository Size
=====================================================================
Removing:
talk x86_64 0.17-46.el7 @base 31 k
Transaction Summary
=====================================================================
Remove 1 Package
Installed size: 31 k
Is this ok [y/N]: y
Downloading packages:
Transaction test succeeded
Running transaction
Erasing : talk-0.17-46.el7.x86_64 1/1
Verifying : talk-0.17-46.el7.x86_64 1/1
Removed:
talk.x86_64 0:0.17-46.el7
Complete!
[root@localhost philip]#

If, for some reason, we want to update all packages on the system, we use the update option:

[root@localhost philip]# yum update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.us.leaseweb.net
* extras: mirror.us.leaseweb.net
* updates: mirror.us.leaseweb.net
Resolving Dependencies
---> Package python-gobject.x86_64 0:3.22.0-1.el7_4.1 will be an update
---> Package python-gobject-base.x86_64 0:3.22.0-1.el7 will be updated
---> Package python-libs.x86_64 0:2.7.5-58.el7 will be updated
---> Package python-libs.x86_64 0:2.7.5-69.el7_5 will be an update
---> Package python-netaddr.noarch 0:0.7.5-7.el7 will be updated
libwayland-server x86_64 1.14.0-2.el7 base 38 k
unbound-libs x86_64 1.6.6-1.el7 base 405 k
volume_key-libs x86_64 0.3.9-8.el7 base 140 k
Transaction Summary
======================================================================================================================================================
Install 6 Packages (+20 Dependent packages)
Upgrade 586 Packages
Total download size: 691 M
Is this ok [y/d/N]: y

Finally, we can view the YUM repo by passing the repolist option:

[root@localhost philip]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.us.leaseweb.net
repo id repo name status
base/7/x86_64 CentOS-7 - Base 9,911
extras/7/x86_64 CentOS-7 - Extras 363
updates/7/x86_64 CentOS-7 - Updates 1,004
repolist: 11,278
[root@localhost philip]#