请选择 进入手机版 | 继续访问电脑版
设为首页收藏本站 JeeStudy企业开发官网①

JEE Study|JAVA EE|企业级开发学习网

 找回密码
 立即加入

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 665|回复: 0

Linux YUM命令详解:Useful yum Command Examples For Package Management In...

[复制链接]

116

主题

118

帖子

823

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
823

最佳新人活跃会员热心会员推广达人宣传达人灌水之王突出贡献优秀版主荣誉管理论坛元老

发表于 2017-8-1 10:13:51 | 显示全部楼层 |阅读模式
YellowdogUpdater Modifier (yum) is an RPM based package manager which is used to installand update packages in various Linux distributions including CentOS, RHEL andFedora.
Yum is quitepowerful as it’s capable of automatically resolving dependency issues, and issimilar to other package managers such as ‘apt-get’ in Debian baseddistributions.
These examplesshould serve as a useful introduction, guide or cheat sheet style resource forhow to use the yum command in Linux.
How To Use yum – Command Examples
·        1. Install New Package From Repository
The yum command can be used to installpackages from a repository with the ‘install’ argument, followed by the packagename. In the example below, we are installing Apache, which is provided in the‘httpd’ package.
[root@centos7 ~]# yum install httpd
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_640:2.4.6-40.el7.centos.4 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================
Package       Arch        Version                   Repository    Size
========================================================================
Installing:
httpd         x86_64     2.4.6-40.el7.centos.4    updates      2.7 M
Transaction Summary
========================================================================
Install 1 Package
Total download size: 2.7 M
Installed size: 9.4 M
Is this ok [y/d/N]: y
Downloading packages:
httpd-2.4.6-40.el7.centos.4.x86_64.rpm        | 2.7 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : httpd-2.4.6-40.el7.centos.4.x86_64            1/1
Verifying  :httpd-2.4.6-40.el7.centos.4.x86_64           1/1
Installed:
httpd.x86_64 0:2.4.6-40.el7.centos.4
Complete!

Note that after confirming the packagesthat will be installed, you will be asked to provide input. In this case weentered ‘y’ for yes to proceed with the installation, which then completedsuccessfully.
·        2. Assume Yes
In the first example we were prompted topress the ‘y’ key in order to proceed with the installation. Rather than beingprompted each time for user input, we can simply specify the ‘-y’ option in ourcommand for assume yes. This way we will not be prompted for any input and yumwill assume that everything will be answered with yes.
[root@centos7 ~]# yum install httpd-manual -y
Resolving Dependencies
--> Running transaction check
---> Package httpd-manual.noarch0:2.4.6-40.el7.centos.4 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================
Package              Arch      Version                  Repository   Size
==========================================================================
Installing:
httpd-manual         noarch    2.4.6-40.el7.centos.4    updates    1.3 M
Transaction Summary
==========================================================================
Install 1 Package
Total download size: 1.3 M
Installed size: 5.5 M
Downloading packages:
httpd-manual-2.4.6-40.el7.centos.4.noarch.rpm      | 1.3 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : httpd-manual-2.4.6-40.el7.centos.4.noarch        1/1
  Verifying  :httpd-manual-2.4.6-40.el7.centos.4.noarch       1/1
Installed:
httpd-manual.noarch 0:2.4.6-40.el7.centos.4
Complete!

Note that in this example we were notprompted for input, as assume yes has been provided, so the package wasinstalled fully without any further user interaction.
·        3. Check For Available Updates
We can run yum with the ‘check-update’argument which will check in with our enabled repositories for any updates thatmay be available for packages that we have installed. This does not actuallyperform any updates, it simply gives us a list of packages that have updatesavailable for installation.
[root@centos7 ~]# yum check-update
Loaded plugins: fastestmirror
Loading mirror speeds from cachedhostfile
bash.x86_64                             4.2.46-20.el7_2        updates
dbus.x86_64                            1:1.6.12-14.el7_2      updates
dbus-libs.x86_64                        1:1.6.12-14.el7_2      updates
device-mapper-persistent-data.x86_64    0.6.2-1.el7_2          updates
glibc.x86_64                           2.17-106.el7_2.8       updates
glibc-common.x86_64                     2.17-106.el7_2.8       updates
initscripts.x86_64                      9.49.30-1.el7_2.3      updates
kernel.x86_64                           3.10.0-327.28.3.el7    updates
kernel-tools.x86_64                     3.10.0-327.28.3.el7    updates
kernel-tools-libs.x86_64                3.10.0-327.28.3.el7    updates
...

·        4. Update New Package From Repository
In the previous example we have beenprovided with a list of packages that currently have package updates available.We can perform an update to a specific package by specifying it after the‘update’ argument, as shown below.
[root@centos7 ~]# yum update bash -y
Resolving Dependencies
--> Running transaction check
---> Package bash.x86_640:4.2.46-19.el7 will be updated
---> Package bash.x86_640:4.2.46-20.el7_2 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================
Package        Arch       Version             Repository   Size
=================================================================
Updating:
bash           x86_64     4.2.46-20.el7_2     updates    1.0 M
Transaction Summary
=================================================================
Upgrade 1 Package
Total download size: 1.0 M
Downloading packages:
Delta RPMs disabled because/usr/bin/applydeltarpm not installed.
bash-4.2.46-20.el7_2.x86_64.rpm        | 1.0 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating   :bash-4.2.46-20.el7_2.x86_64           1/2
Cleanup    :bash-4.2.46-19.el7.x86_64             2/2
Verifying  :bash-4.2.46-20.el7_2.x86_64           1/2
Verifying  :bash-4.2.46-19.el7.x86_64             2/2
Updated:
bash.x86_64 0:4.2.46-20.el7_2
Complete!

Note that we do not have to runcheck-update prior to this.
While we can update specified packagesin this manner, it is often easier to simply apply all available updates forall packages on the system with ‘yum update’.
·        5. Download Package RPM File
Rather than installing a package fromthe repository as demonstrated previously, we can optionally download the .rpmfile from the repository with the ‘yumdownloader’ command.
The ‘yumdownloader’ command comes fromthe ‘yum-utils’ package, so we install this first.
[root@centos7 ~]# yum install yum-utils -y

Now we can download the RPM file to thelocal system.
[root@centos7 ~]# yumdownloader unbound
Loaded plugins: fastestmirror
Loading mirror speeds from cachedhostfile
*base: mirror.ventraip.net.au
*extras: mirror.optus.net
*updates: mirror.optus.net
unbound-1.4.20-26.el7.x86_64.rpm
[root@centos7 ~]# ls -la unbound-1.4.20-26.el7.x86_64.rpm
-rw-r--r--. 1 root root 483136 Nov26  2015 unbound-1.4.20-26.el7.x86_64.rpm

·        6. Perform Local Install Of RPM File
In this example we will install the .rpmfile that we just downloaded with ‘yumdownloader’. While we could have justinstalled this package from the repository directly with ‘yum install’,sometimes you may be provided with .rpm files directly for installation so it’sworth knowing how to install them.
While .rpm files can be installed withthe ‘rpm’ command, using yum has the advantage of automatically detecting andinstalling any other package dependencies that may also be required.
[root@centos7 ~]# yum localinstall unbound-1.4.20-26.el7.x86_64.rpm
Loaded plugins: fastestmirror
Examiningunbound-1.4.20-26.el7.x86_64.rpm: unbound-1.4.20-26.el7.x86_64
Marking unbound-1.4.20-26.el7.x86_64.rpmto be installed
Resolving Dependencies
--> Running transaction check
---> Package unbound.x86_640:1.4.20-26.el7 will be installed
--> Processing Dependency:unbound-libs(x86-64) = 1.4.20-26.el7 for package: unbound-1.4.20-26.el7.x86_64
Loading mirror speeds from cachedhostfile
*base: mirror.ventraip.net.au
*extras: mirror.optus.net
*updates: mirror.optus.net
--> Processing Dependency: ldns >=1.6.13 for package: unbound-1.4.20-26.el7.x86_64
--> Processing Dependency:libevent-2.0.so.5()(64bit) for package: unbound-1.4.20-26.el7.x86_64
--> Processing Dependency: libldns.so.1()(64bit)for package: unbound-1.4.20-26.el7.x86_64
--> Processing Dependency:libunbound.so.2()(64bit) for package: unbound-1.4.20-26.el7.x86_64
--> Running transaction check
---> Package ldns.x86_640:1.6.16-7.el7 will be installed
---> Package libevent.x86_640:2.0.21-4.el7 will be installed
---> Package unbound-libs.x86_640:1.4.20-26.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================
Package          Arch       Version             Repository                         Size
=========================================================================================
Installing:
unbound          x86_64     1.4.20-26.el7       /unbound-1.4.20-26.el7.x86_64     1.6 M
Installing for dependencies:
ldns             x86_64     1.6.16-7.el7        base                              473 k
libevent         x86_64     2.0.21-4.el7        base                              214 k
unbound-libs     x86_64    1.4.20-26.el7       base                              296 k
Transaction Summary
=========================================================================================
Install 1 Package (+3 Dependent packages)
Total size: 2.6 M
Total download size: 982 k
Installed size: 4.4 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3):unbound-libs-1.4.20-26.el7.x86_64.rpm                      | 296 kB  00:00:00
(2/3): ldns-1.6.16-7.el7.x86_64.rpm                               | 473 kB  00:00:00
(3/3):libevent-2.0.21-4.el7.x86_64.rpm                           | 214 kB  00:00:00
-----------------------------------------------------------------------------------------
Total                                                      1.5 MB/s | 982 kB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ldns-1.6.16-7.el7.x86_64                                             1/4
Installing : libevent-2.0.21-4.el7.x86_64                                          2/4
Installing : unbound-libs-1.4.20-26.el7.x86_64                                     3/4
Installing : unbound-1.4.20-26.el7.x86_64                                          4/4
Verifying  :unbound-1.4.20-26.el7.x86_64                                          1/4
Verifying  :unbound-libs-1.4.20-26.el7.x86_64                                     2/4
Verifying  :libevent-2.0.21-4.el7.x86_64                                          3/4
Verifying  :ldns-1.6.16-7.el7.x86_64                                             4/4
Installed:
unbound.x86_64 0:1.4.20-26.el7
Dependency Installed:
ldns.x86_64 0:1.6.16-7.el7                    libevent.x86_640:2.0.21-4.el7
unbound-libs.x86_64 0:1.4.20-26.el7
Complete!

·        7. Uninstall Package
Packages can be uninstalled with the‘remove’ argument, as shown below.
[root@centos7 ~]# yum remove httpd
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_640:2.4.6-40.el7.centos.4 will be erased
--> Processing Dependency: httpd =2.4.6-40.el7.centos.4 for package: httpd-manual-2.4.6-40.el7.centos.4.noarch
--> Running transaction check
---> Package httpd-manual.noarch0:2.4.6-40.el7.centos.4 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================
Package                                      Arch                                   Version                                                 Repository                               Size
=============================================================================================================================================================================================
Removing:
httpd                                       x86_64                                 2.4.6-40.el7.centos.4                                   @updates                                9.4 M
Removing for dependencies:
httpd-manual                                 noarch                                 2.4.6-40.el7.centos.4                                   @updates                                5.5 M
Transaction Summary
=============================================================================================================================================================================================
Remove 1 Package (+1 Dependent package)
Installed size: 15 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing    :httpd-manual-2.4.6-40.el7.centos.4.noarch                                                                                                                                1/2
Erasing    :httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        2/2
Verifying  :httpd-manual-2.4.6-40.el7.centos.4.noarch                                                                                                                                1/2
Verifying  :httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                       2/2
Removed:
  httpd.x86_640:2.4.6-40.el7.centos.4
Dependency Removed:
httpd-manual.noarch 0:2.4.6-40.el7.centos.4
Complete!

Note that in order to remove a package,all other packages which depend on it will also be removed. For that reason itis recommended not to use the -y option to ‘assumeyes’ when removing a packageso that you get a chance to read what will be removed before proceeding, as itmay be more than you expect.
In the above example, the httpd-manualpackage that we installed previously requires the httpd package. Therefore whenwe remove the httpd package, httpd-manual must go too.
·        8. Reinstall Package
If you’re having a problem with apackage, you can easily reinstall it with the ‘reinstall’ argument.
[root@centos7 ~]# yum reinstall httpd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cachedhostfile
*base: mirror.ventraip.net.au
*extras: mirror.optus.net
*updates: mirror.optus.net
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_640:2.4.6-40.el7.centos.4 will be reinstalled
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================
Package                                 Arch                                    Version                                                   Repository                                 Size
=============================================================================================================================================================================================
Reinstalling:
httpd                                   x86_64                                   2.4.6-40.el7.centos.4                                     updates                                  2.7 M
Transaction Summary
=============================================================================================================================================================================================
Reinstall  1 Package
Total download size: 2.7 M
Installed size: 9.4 M
Downloading packages:
httpd-2.4.6-40.el7.centos.4.x86_64.rpm                                                                                                                                |2.7 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        1/1
Verifying  :httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                       1/1
Installed:
httpd.x86_64 0:2.4.6-40.el7.centos.4
Complete!

This is similar to performing a ‘yumremove’ followed by a ‘yum install’, however here it’s done in the one commandand custom configuration is not removed, as a ‘yum remove’ will delete allconfiguration files managed by the package.
·        9. View Repository Information
By default we have many repositoriesconfigured in the /etc/yum.repos.d/ directory, these can be viewed with the ‘repolist’and ‘repoinfo’ arguments.
[root@centos7 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cachedhostfile
*base: mirror.ventraip.net.au
*extras: mirror.optus.net
*updates: mirror.optus.net
repo id                 repo name               status
base/7/x86_64           CentOS-7 - Base         9,007
extras/7/x86_64         CentOS-7 - Extras       375
updates/7/x86_64        CentOS-7 - Updates      2,303
repolist: 11,685

By default ‘repolist’ displaysinformation for enabled repositories only, however we can specify ‘all’afterwards to list even disabled repositories.
[root@centos7 ~]# yum repolist all
repo id                      repo name                   status
base/7/x86_64                CentOS-7 - Base             enabled: 9,007
base-debuginfo/x86_64        CentOS-7 - Debuginfo        disabled
base-source/7                CentOS-7 - Base Sources     disabled
c7-media                     CentOS-7 - Media            disabled
centosplus/7/x86_64          CentOS-7 - Plus             disabled
...

Further information on a specificrepository can then be viewed with ‘repoinfo’ followed by the repo name thatyou want to query.
[root@centos7 ~]# yum repoinfo CentOS-7 - Base
Loaded plugins: fastestmirror
Loading mirror speeds from cachedhostfile
*base: mirror.ventraip.net.au
*extras: mirror.optus.net
*updates: mirror.optus.net
Repo-id      : base/7/x86_64
Repo-name    : CentOS-7 - Base
Repo-status  : enabled
Repo-revision: 1449700451
Repo-updated : Thu Dec 10 09:35:45 2015
Repo-pkgs    : 9,007
Repo-size    : 6.5 G
Repo-expire  : 21,600 second(s) (last: Mon Aug 29 14:25:352016)
Repo-filename:/etc/yum.repos.d/CentOS-Base.repo
repolist: 9,007

·        10. Add New Repository
We can specify a new repository bymanually editing or creating a new .repo file in the /etc/yum.repos.ddirectory, however we can much more easily create a persistent repository withthe yum-config-manager command. This command comes from the ‘yum-utils’ packagewhich we installed previously, so if you wish to use ‘yum-config-manager’ besure to first install ‘yum-utils’.
[root@centos7 ~]# yum-config-manager--add-repo="https://mirror.aarnet.edu.au/pub/centos/7"
Loaded plugins: fastestmirror
[mirror.aarnet.edu.au_pub_centos_7]
baseurl=https://mirror.aarnet.edu.au/pub/centos/7
enabled=1

We simply provide a known repository URLin the –add-repo option, and this creates a .repo file based on the name of therepository URL specified. In this case,/etc/yum.repos.d/mirror.aarnet.edu.au_pub_centos_7.repo has been created withthe contents specified above in the output of the command. We can now installor update packages from this newly specified mirror.
·        11. Enable Or Disable Specific Repository
There may be times when we want toperform an action while enabling or disabling a specific repository. Forexample if we want to install a particular package, we may want to ensure thatit comes from a specific mirror.
yum --enablerepo=disabled-repo installpackage-example

This would enabled a previously disabledrepo named ‘disabled-repo’ in order to install ‘package-example’ from it.
If we have the same packages availableat multiple repositories we may wish to disable one and update or install froma specific repository. This can be done by disabling the repository with--disablerepo.
yum --disablerepo=enabled-repo installpackage-example

·        12. Search For Packages In Repository
The ‘search’ argument is a very usefulyum feature, as it allows us to search through packages on the repository whichcan be useful if we don’t know exactly what we’re looking to install.
[root@centos7 ~]# yum search php
=====================================================================================N/S matched: php======================================================================================
graphviz-php.x86_64 : PHP extension forgraphviz
php.x86_64 : PHP scripting language forcreating dynamic web sites
php-bcmath.x86_64 : A module for PHPapplications for using the bcmath library
php-cli.x86_64 : Command-line interfacefor PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstractionlayer module for PHP applications
php-devel.x86_64 : Files needed forbuilding PHP extensions
php-embedded.x86_64 : PHP library forembedding in applications
php-enchant.x86_64 : Enchant spellingextension for PHP applications
php-fpm.x86_64 : PHP FastCGI ProcessManager
php-gd.x86_64 : A module for PHPapplications for using the gd graphics library
...
Name and summary matches only, use "search all" foreverything.

In this example we search package namesand the summary for the term “PHP” and see a number of available packages atthe repositories ready for us to install or download.
·        13. Find Which Package Provides Something
This is one of my favourite features ofthe yum command as it’s very useful. Have you ever wanted to run a command, butyou’re not sure which package is required for it? This is where the ‘provides’argument comes in use.
In this example we want to create aniSCSI initiator, this is done with the ‘iscsiadm’ command. We can use‘provides’ followed by the name of the command to search for packages thatprovide this command.
[root@centos7 ~]# yum provides iscsiadm
iscsi-initiator-utils-6.2.0.873-32.el7.i686: iSCSI daemon and utility programs
Repo        : base
Matched from:
Filename    : /usr/sbin/iscsiadm

As shown the ‘iscsi-initiator-utils’package can be installed to provide the ‘iscsiadm’ command.
This can also be used against a file onthe file system to check which package provides that file.
[root@centos7 ~]# yum provides /etc/httpd/conf/httpd.conf
httpd-2.4.6-40.el7.centos.x86_64 :Apache HTTP Server
Repo        : base
Matched from:
Filename    : /etc/httpd/conf/httpd.conf

In this example we can see that the/etc/httpd/conf/httpd.conf file comes from the ‘httpd’ package.
·        14. View Package Information
Further detailed information of apackage can be viewed with the ‘info’ argument. As shown below, this providesus with useful information such as the architecture, version number, releasenumber, total size, as well as a description of what the package actually does.
[root@centos7 ~]# yum info httpd
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.6
Release     : 40.el7.centos.4
Size        : 2.7 M
Repo        : updates/7/x86_64
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server isa powerful, efficient, and extensible
            : web server.

This can be used before a package isinstalled or after installation, the same information will be provided in bothsituations.
·        15. View Transaction History
The yum history contains all actionsthat have been performed by the yum command. This allows us to see what hashappened to our Linux system over time, and even undo, redo, or roll back atransaction.
[root@centos7 ~]# yum history
ID    | Login user      | Date andtime    | Action(s)      | Altered
------------------------------------------------------------------------
   15 | root            | 2016-08-2915:20 | Erase          |    1
   14 | root            | 2016-08-2914:55 | Install        |    1
   13 | root            | 2016-08-2914:55 | Erase          |    1 EE
   12 | root            | 2016-08-2914:54 | Reinstall      |    1
   11 | root            | 2016-08-2914:54 | Install        |   31
   10 | root            | 2016-08-2914:53 | Install        |    1
    9 | root            | 2016-08-2914:47 | Erase          |    2
    8 | root            | 2016-08-2914:45 | Install        |    4
    7 | root            | 2016-08-2914:40 | Install        |    3
    6 | root            | 2016-08-2914:37 | Update         |    1
    5 | root            | 2016-08-2914:32 | Install        |    1
    4 | root            | 2016-08-2914:28 | Install        |    1
    3 | root            | 2016-08-2914:28 | Erase          |    1
    2 | root            | 2016-08-2914:28 | Install        |    5
    1 | System          | 2016-08-2914:17 | Install        |  298
history list

The newest transactions appear at thetop of the list, and we can view further information of a transaction byspecifying its ID, as shown below.
[root@centos7 ~]# yum history info 15
Transaction ID : 15
Begin time     : Mon Aug 29 15:20:57 2016
Begin rpmdb    :341:c62a7835aef7986909a89bc51d654acf51b8d756
End time       :                           (0 seconds)
End rpmdb      :340:8701e1360e8e5403f96a5cc61994740ba7d8daf8
User           : root
Return-Code    : Success
Command Line   : remove httpd -y
Transaction performed with:
   Installed    rpm-4.11.3-17.el7.x86_64                      @anaconda
   Installed    yum-3.4.3-132.el7.centos.0.1.noarch           @anaconda
   Installed    yum-plugin-fastestmirror-1.1.31-34.el7.noarch @anaconda
Packages Altered:
   Erase httpd-2.4.6-40.el7.centos.4.x86_64 @updates
history info

So the most recent transaction with theID of 15 was used to remove the httpd package. Now we can undo this transactionif we want, which should install the httpd package again, as this will undo theremoval.
[root@centos7 ~]# yum history undo 15 -y
Undoing transaction 15, from Mon Aug 2915:20:57 2016
   Erase httpd-2.4.6-40.el7.centos.4.x86_64 @updates
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_640:2.4.6-40.el7.centos.4 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================
Package              Arch      Version                 Repository    Size
============================================================================
Installing:
httpd               x86_64    2.4.6-40.el7.centos.4    updates       2.7 M
Transaction Summary
============================================================================
Install 1 Package
Total download size: 2.7 M
Installed size: 9.4 M
Downloading packages:
httpd-2.4.6-40.el7.centos.4.x86_64.rpm                   | 2.7 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : httpd-2.4.6-40.el7.centos.4.x86_64                       1/1
Verifying  :httpd-2.4.6-40.el7.centos.4.x86_64                       1/1
Installed:
httpd.x86_64 0:2.4.6-40.el7.centos.4
Complete!

We can then run the removal again with‘yum history redo’.
[root@centos7 ~]# yum history redo 15 -y
Repeating transaction 15, from Mon Aug29 15:20:57 2016
   Erase httpd-2.4.6-40.el7.centos.4.x86_64 @updates
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_640:2.4.6-40.el7.centos.4 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================
Package              Arch       Version                Repository   Size
==========================================================================
Removing:
httpd                x86_64     2.4.6-40.el7.centos.4  @updates   9.4 M
Transaction Summary
==========================================================================
Remove 1 Package
Installed size: 9.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing    :httpd-2.4.6-40.el7.centos.4.x86_64  1/1
Verifying  :httpd-2.4.6-40.el7.centos.4.x86_64  1/1
Removed:
httpd.x86_64 0:2.4.6-40.el7.centos.4
Complete!

It’s also worth noting that packageinstallations, updates, or removals are also logged in the /var/log/yum.logfile, here’s an example of what’s logged here.
[root@centos7 ~]# tail /var/log/yum.log
Aug 29 14:28:24 Installed:httpd-2.4.6-40.el7.centos.4.x86_64
Aug 29 14:28:29 Erased:httpd-2.4.6-40.el7.centos.4.x86_64
Aug 29 14:28:41 Installed:httpd-2.4.6-40.el7.centos.4.x86_64
Aug 29 14:32:55 Installed:httpd-manual-2.4.6-40.el7.centos.4.noarch
Aug 29 14:37:28 Updated:bash-4.2.46-20.el7_2.x86_64

·        16. Clear Cached Information
By default yum will cache data to the/var/cache/yum directory, such as package and repository data. This speeds upyum so that it doesn’t have to keep querying this information from theInternet.
There are times when you may want todelete this cached data, such as if a repository has updated packages but yourLinux system has incorrect or stale cached data which may cause variousproblems when attempting to install a package.
[root@centos7 ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors

This will remove all cached items, it ispossible to otherwise specify specific elements to clear (such as packages,metadata, expire-cache, rpmdb or plugins) however this saves a lot of time ifyou aren’t sure what should be removed.
·        17. Build Cache
The yum cache will be automaticallybuilt up over time when you perform various yum queries such as installing orupdating packages, however we have the option to manually make the cache sothat future actions will be quicker with the ‘makecache’ argument.
[root@centos7 ~]# time yum makecache
Loaded plugins: fastestmirror, langpacks
base                                            |3.6 kB  00:00:00
extras                                          | 3.4kB  00:00:00
updates                                         | 3.4 kB 00:00:00
(1/12): base/7/x86_64/group_gz                  | 155 kB  00:00:00
(2/12): extras/7/x86_64/prestodelta             | 72 kB  00:00:00
(3/12):extras/7/x86_64/filelists_db            |426 kB  00:00:00
(4/12): extras/7/x86_64/primary_db              | 160 kB  00:00:00
(5/12): base/7/x86_64/filelists_db              | 6.2 MB  00:00:01
(6/12): extras/7/x86_64/other_db                | 652 kB  00:00:00
(7/12): base/7/x86_64/other_db                  | 2.3 MB  00:00:01
(8/12): updates/7/x86_64/prestodelta            | 698 kB  00:00:00
(9/12): base/7/x86_64/primary_db                | 5.3 MB  00:00:01
(10/12):updates/7/x86_64/filelists_db          |4.4 MB  00:00:01
(11/12):updates/7/x86_64/primary_db            |7.1 MB  00:00:01
(12/12): updates/7/x86_64/other_db              | 61 MB  00:00:07
Determining fastest mirrors
*base: centos.mirror.crucial.com.au
*extras: centos.mirror.crucial.com.au
*updates: centos.mirror.crucial.com.au
Metadata Cache Created
real   0m40.785s
user   0m32.504s
sys    0m1.937s

We can also add the ‘fast’ option to theend, which will take less time but only cache fewer repositories.
[root@centos7 ~]# time yum makecache fast
Loaded plugins: fastestmirror, langpacks
base                                     | 3.6 kB 00:00:00
extras                                   | 3.4kB  00:00:00
updates                                  | 3.4 kB  00:00:00
(1/4): base/7/x86_64/group_gz            | 155 kB  00:00:00
(2/4): extras/7/x86_64/primary_db        | 160 kB  00:00:00
(3/4): base/7/x86_64/primary_db          | 5.3 MB  00:00:00
(4/4): updates/7/x86_64/primary_db       | 7.1 MB 00:00:01
Determining fastest mirrors
*base: mirror.nsw.coloau.com.au
*extras: mirror.nsw.coloau.com.au
*updates: mirror.nsw.coloau.com.au
Metadata Cache Created
real   0m8.879s
user   0m3.451s
sys    0m0.343s

As we can see the fast cache wassignificantly faster.
·        18. List Installed Packages
We have the ability to list all packagesthat are currently installed on our Linux system with ‘yum list installed’. Ihave not included the full output here as I have hundreds of packages installedon my system, however this small snippet should give you an idea of what toexpect.
[root@centos7 ~]# yum list installed | head -n 15
Installed Packages
NetworkManager.x86_64                1:1.0.6-30.el7_2             @anaconda
NetworkManager-libnm.x86_64          1:1.0.6-30.el7_2             @anaconda
NetworkManager-team.x86_64           1:1.0.6-30.el7_2             @anaconda
NetworkManager-tui.x86_64            1:1.0.6-30.el7_2             @anaconda
NetworkManager-wifi.x86_64           1:1.0.6-30.el7_2             @anaconda
acl.x86_64                           2.2.51-12.el7                @anaconda
aic94xx-firmware.noarch              30-6.el7                     @anaconda
alsa-firmware.noarch                 1.0.28-2.el7                 @anaconda
alsa-lib.x86_64                      1.0.28-2.el7                 @anaconda
alsa-tools-firmware.x86_64           1.0.28-2.el7                 @anaconda
apr.x86_64                           1.4.8-3.el7                  @base
apr-util.x86_64                      1.5.2-6.el7                  @base
audit.x86_64                         2.4.1-5.el7                  @anaconda
...

When piped into the grep command thisbecomes extremely powerful as it allows us to search for a specific package tosee if it is installed.
[root@centos7 ~]# yum list installed | grep httpd
httpd.x86_64                        2.4.6-40.el7.centos.4         @updates
httpd-tools.x86_64                   2.4.6-40.el7.centos.4          @updates

·        19. List Available Packages
In the above example we learned how tolist currently installed packages on our Linux system with the yum command, nowwe want to be able to query a repository and list its available packagesinstead.
This is quite similar, except that wereplace ‘installed’ with ‘available’ to instead list all available packages.
[root@centos7 ~]# yum list installed | wc -l
343
[root@centos7 ~]# yum list available | wc -l
8972

As we can see we have over 300 packagescurrently installed, however in the repository there are almost 9000 packagesin total for us to install.
We can also run ‘yum list all’ to listboth installed and available packages together, or ‘yum list updates’ to onlylist packages which currently have updates available, the output of which issimilar to the ‘yum check-update’ command covered previously.
·        20. Package Groups
Packages that are related to each othermay be grouped together into a package group. This allows us to install,update, or remove the package group which is actually made up or many otherindividual packages.
For example we can run ‘yum grouplist’to view the groups that are available for us to use by default.
[root@centos7 ~]# yum grouplist
There is no installed groups file.
Maybe run: yum groups mark convert (seeman yum)
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

Once we have the list of availablegroups, we can use ‘yum groupinfo’ on any of them to get an idea of thepackages that are included as part of the group.
[root@centos7 ~]# yum groupinfo "Basic Web Server"
There is no installed groups file.
Maybe run: yum groups mark convert (seeman yum)
Environment Group: Basic Web Server
Environment-Id: web-server-environment
Description: Server for serving static anddynamic internet content.
Mandatory Groups:
  +base
  +core
  +web-server
[root@centos7 ~]# yum groupinfo "web-server"
There is no installed groups file.
Maybe run: yum groups mark convert (seeman yum)
Group: Web Server
Group-Id: web-server
Description: Allows the system to act as a webserver, and run Perl and Python web applications.
Mandatory Packages:
   httpd
Default Packages:
  +crypto-utils
  +httpd-manual
  +mod_fcgid
  +mod_ssl

Here we can see the “Basic Web Server”group is actually made up of three other groups, base, core, and web-server. Ifwe look closer at the web-server group we can see that it uses the httpdpackage as well as some additional ones that we do not yet have installed butare available, as denoted by the ‘+’ symbol.
Finally we can install the group withthe ‘yum groupinstall’ command, as shown below.
[root@centos7 ~]# yum groupinstall "web server" -y
There is no installed groups file.
Maybe run: yum groups mark convert (seeman yum)
Resolving Dependencies
--> Running transaction check
---> Package crypto-utils.x86_640:2.4.1-42.el7 will be installed
--> Processing Dependency: perl(Newt)for package: crypto-utils-2.4.1-42.el7.x86_64
---> Package httpd-manual.noarch0:2.4.6-40.el7.centos.4 will be installed
---> Package mod_fcgid.x86_640:2.3.9-4.el7 will be installed
---> Package mod_ssl.x86_641:2.4.6-40.el7.centos.4 will be installed
--> Running transaction check
---> Package perl-Newt.x86_640:1.08-36.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================
Package                                      Arch                                   Version                                                  Repository                              Size
=============================================================================================================================================================================================
Installing for group install "WebServer":
crypto-utils                                 x86_64                                2.4.1-42.el7                                             base                                     78 k
httpd-manual                                 noarch                                2.4.6-40.el7.centos.4                                    updates                                1.3 M
mod_fcgid                                    x86_64                                2.3.9-4.el7                                              base                                    79 k
mod_ssl                                     x86_64                                1:2.4.6-40.el7.centos.4                                   updates                                 104 k
Installing for dependencies:
perl-Newt                                    x86_64                                1.08-36.el7                                              base                                     64 k
Transaction Summary
=============================================================================================================================================================================================
Install 4 Packages (+1 Dependent package)
Total download size: 1.6 M
Installed size: 6.2 M
Downloading packages:
(1/5):crypto-utils-2.4.1-42.el7.x86_64.rpm                                                                                                                          |  78 kB 00:00:00
(2/5):perl-Newt-1.08-36.el7.x86_64.rpm                                                                                                                              |  64 kB  00:00:00
(3/5): mod_fcgid-2.3.9-4.el7.x86_64.rpm                                                                                                                              |  79 kB  00:00:00
(4/5):mod_ssl-2.4.6-40.el7.centos.4.x86_64.rpm                                                                                                                       |104 kB  00:00:00
(5/5):httpd-manual-2.4.6-40.el7.centos.4.noarch.rpm                                                                                                                 | 1.3 MB  00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        2.5MB/s | 1.6 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : perl-Newt-1.08-36.el7.x86_64                                                                                                                                             1/5
Installing : crypto-utils-2.4.1-42.el7.x86_64                                                                                                                                          2/5
Installing : 1:mod_ssl-2.4.6-40.el7.centos.4.x86_64                                                                                                                                   3/5
Installing : httpd-manual-2.4.6-40.el7.centos.4.noarch                                                                                                                                4/5
Installing : mod_fcgid-2.3.9-4.el7.x86_64                                                                                                                                             5/5
Verifying  :perl-Newt-1.08-36.el7.x86_64                                                                                                                                             1/5
Verifying  :mod_fcgid-2.3.9-4.el7.x86_64                                                                                                                                             2/5
Verifying  :crypto-utils-2.4.1-42.el7.x86_64                                                                                                                                         3/5
Verifying  :httpd-manual-2.4.6-40.el7.centos.4.noarch                                                                                                                                4/5
Verifying  :1:mod_ssl-2.4.6-40.el7.centos.4.x86_64                                                                                                                                   5/5
Installed:
crypto-utils.x86_64 0:2.4.1-42.el7          httpd-manual.noarch0:2.4.6-40.el7.centos.4         mod_fcgid.x86_64 0:2.3.9-4.el7         mod_ssl.x86_64 1:2.4.6-40.el7.centos.4
Dependency Installed:
perl-Newt.x86_64 0:1.08-36.el7
Complete!

The group can also be updated with ‘yumgroupupdate’, or all packages within the group removed with ‘yum groupremove’.
·        21. Install Security Updates Only
While we can simply perform a ‘yumupdate’ to update all of our installed packages to the latest versions, thismay not be ideal in a production environment. Being able to install securityonly updates during patching may be a requirement in your environment, and canbe done with ‘yum update --security’.
[root@centos7 ~]# yum update --security

·        22. Exclude Specific Package
We can optionally exclude a specificpackage from update, installation or removal with the -x command which willexclude that package. In this example, we perform a ‘yum check-update’ andconfirm that a kernel update is available, however we do not wish to installthis package at this time. With the help of -x, we ignore the kernel update andinstead perform a ‘yum update’ which states that it is going to updateeverything except the kernel, which is not listed.
[root@centos7 ~]# yum check-update
device-mapper-persistent-data.x86_64                                                              0.6.2-1.el7_2                                                                      updates
initscripts.x86_64                                                                                9.49.30-1.el7_2.3                                                                 updates
kernel.x86_64                                                                                      3.10.0-327.28.3.el7                                                               updates
kernel-tools.x86_64                                                                               3.10.0-327.28.3.el7                                                               updates
kernel-tools-libs.x86_64                                                                          3.10.0-327.28.3.el7                                                                updates
microcode_ctl.x86_64                                                                              2:2.1-12.el7_2.1                                                                  updates
python-perf.x86_64                                                                                 3.10.0-327.28.3.el7                                                               updates
[root@centos7 ~]# yum update -x kernel
Resolving Dependencies
--> Running transaction check
---> Packagedevice-mapper-persistent-data.x86_64 0:0.5.5-1.el7 will be updated
---> Packagedevice-mapper-persistent-data.x86_64 0:0.6.2-1.el7_2 will be an update
---> Package initscripts.x86_640:9.49.30-1.el7_2.2 will be updated
---> Package initscripts.x86_640:9.49.30-1.el7_2.3 will be an update
---> Package kernel-tools.x86_640:3.10.0-327.22.2.el7 will be updated
---> Package kernel-tools.x86_640:3.10.0-327.28.3.el7 will be an update
---> Package kernel-tools-libs.x86_640:3.10.0-327.22.2.el7 will be updated
---> Package kernel-tools-libs.x86_640:3.10.0-327.28.3.el7 will be an update
---> Package microcode_ctl.x86_642:2.1-12.el7 will be updated
---> Package microcode_ctl.x86_642:2.1-12.el7_2.1 will be an update
---> Package python-perf.x86_640:3.10.0-327.22.2.el7 will be updated
---> Package python-perf.x86_640:3.10.0-327.28.3.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================
Package                                                   Arch                               Version                                          Repository                            Size
=============================================================================================================================================================================================
Updating:
device-mapper-persistent-data                              x86_64                             0.6.2-1.el7_2                                     updates                              366 k
initscripts                                               x86_64                              9.49.30-1.el7_2.3                                 updates                              429 k
kernel-tools                                              x86_64                             3.10.0-327.28.3.el7                               updates                              2.4 M
kernel-tools-libs                                         x86_64                             3.10.0-327.28.3.el7                               updates                              2.3 M
microcode_ctl                                              x86_64                             2:2.1-12.el7_2.1                                  updates                              535 k
python-perf                                               x86_64                             3.10.0-327.28.3.el7                               updates                              2.4 M
Transaction Summary
=============================================================================================================================================================================================
Upgrade 6 Packages
Total download size: 8.4 M
Is this ok [y/d/N]:

·        23. Add Random Wait Time
There are times where you may want toinsert a random period of time before performing some yum command, for exampleif you manage hundreds of servers and go to update them all on a particular dayyou probably don’t want them all to hit the repository at the same time as thismay cause the process to run very slow. With the -R option we can specify amaximum random time in minutes that yum will wait before executing the command,somewhere within this time period will be selected at random.
[root@centos7 ~]# time yum remove httpd -y -R 2
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_640:2.4.6-40.el7.centos.4 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================
Package                                 Arch                                    Version                                                  Repository                                  Size
=============================================================================================================================================================================================
Removing:
httpd                                   x86_64                                   2.4.6-40.el7.centos.4                                    @updates                                   9.4 M
Transaction Summary
=============================================================================================================================================================================================
Remove 1 Package
Installed size: 9.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing    :httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                       1/1
Verifying  :httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        1/1
Removed:
httpd.x86_64 0:2.4.6-40.el7.centos.4
Complete!
real   1m21.954s
user   0m0.409s
sys    0m0.156s

In this example I appended the ‘time’command to the ‘yum’ command so that we could see how long it took to complete,in this example we can see that this took approximately 1 minute and 22 secondsto complete, which is a random period from 0 to 2 minutes as was specified.
·        24. Hide All Output
As you have seen in the above examples,the yum command can provide quite a bit of output. If we don’t want to displaythe output messages we can simply specify the -q option for quiet which willhide all of the output. In the example below we completely uninstall a packagewith yum and have no messages output.
[root@centos7 ~]# yum install httpd -y -q
[root@centos7 ~]#

·        25. Display Verbose Information
Alternatively if you’re troubleshootingyou can specify the -v option to enable verbose output. In the below verboseexample we can see additional information in the output that was not previouslyavailable.
[root@centos7 ~]# yum remove httpd -y -v
Loading "fastestmirror" plugin
Config time: 0.007
Yum version: 3.4.3
rpmdb time: 0.000
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_640:2.4.6-40.el7.centos.4 will be erased
Checking deps for httpd.x86_640:2.4.6-40.el7.centos.4 - e
--> Finished Dependency Resolution
Dependency Process ending
Depsolve time: 0.220
Dependencies Resolved
=========================================================================
Package              Arch       Version                Repository   Size
=========================================================================
Removing:
httpd                x86_64     2.4.6-40.el7.centos.4  @updates   9.4 M
Transaction Summary
=========================================================================
Remove 1 Package
Installed size: 9.4 M
Downloading packages:
Member: httpd.x86_640:2.4.6-40.el7.centos.4 - e
Removing Packagehttpd-2.4.6-40.el7.centos.4.x86_64
Running transaction check
Transaction check time: 0.001
Running transaction test
Transaction test succeeded
Transaction test time: 0.014
Running transaction
Erasing    :httpd-2.4.6-40.el7.centos.4.x86_64    1/1
Verifying  :httpd-2.4.6-40.el7.centos.4.x86_64    1/1
VerifyTransaction time: 0.049
Transaction time: 0.425
Removed:
httpd.x86_64 0:2.4.6-40.el7.centos.4
Complete!

Summary
This guide hascovered how to use yum with 25 different examples in which you can practicallyput the yum command to use.



知识改变命运!

JAVA EE 学习     JAVA EE 资料
JEE Study:企业级开发学习网!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

本版积分规则

QQ|Archiver|手机版|小黑屋|JEE Study ( 京ICP备16036936   JeeStudy企业开发官网①

GMT+8, 2019-9-24 03:45 , Processed in 0.220694 second(s), 36 queries .

Powered by JeeStudy!

© 2016 JEE Study 企业级开发学习网

快速回复 返回顶部 返回列表