玩转YUM–30个YUM常用命令(三)

21 使用YUM列出所有YUM存储库
使用yum与all选项可以为您提供系统上配置的所有存储库的列表,包括禁用的存储库。
[root@localhost ~]# yum repolist all
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
repo id repo name status
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base disabled
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus disabled
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras disabled
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus disabled
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates disabled
C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base disabled
C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus disabled
C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras disabled
C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus disabled
C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates disabled
C7.2.1511-base/x86_64 CentOS-7.2.1511 - Base disabled
C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus disabled
C7.2.1511-extras/x86_64 CentOS-7.2.1511 - Extras disabled
C7.2.1511-fasttrack/x86_64 CentOS-7.2.1511 - CentOSPlus disabled
C7.2.1511-updates/x86_64 CentOS-7.2.1511 - Updates disabled
C7.3.1611-base/x86_64 CentOS-7.3.1611 - Base disabled
C7.3.1611-centosplus/x86_64 CentOS-7.3.1611 - CentOSPlus disabled
C7.3.1611-extras/x86_64 CentOS-7.3.1611 - Extras disabled
C7.3.1611-fasttrack/x86_64 CentOS-7.3.1611 - CentOSPlus disabled
C7.3.1611-updates/x86_64 CentOS-7.3.1611 - Updates disabled
C7.4.1708-base/x86_64 CentOS-7.4.1708 - Base disabled
C7.4.1708-centosplus/x86_64 CentOS-7.4.1708 - CentOSPlus disabled
C7.4.1708-extras/x86_64 CentOS-7.4.1708 - Extras disabled
C7.4.1708-fasttrack/x86_64 CentOS-7.4.1708 - CentOSPlus disabled
C7.4.1708-updates/x86_64 CentOS-7.4.1708 - Updates disabled
Webmin Webmin Distribution Neutral enabled: 119
base/7/x86_64 CentOS-7 - Base enabled: 9,911
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
centosplus-source/7 CentOS-7 - Plus Sources disabled
cr/7/x86_64 CentOS-7 - cr disabled
epel/x86_64 Extra Packages for Enterprise Linux 7 - enabled: 12,687
epel-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - disabled
epel-source/x86_64 Extra Packages for Enterprise Linux 7 - disabled
epel-testing/x86_64 Extra Packages for Enterprise Linux 7 - disabled
epel-testing-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - disabled
epel-testing-source/x86_64 Extra Packages for Enterprise Linux 7 - disabled
extras/7/x86_64 CentOS-7 - Extras enabled: 403
extras-source/7 CentOS-7 - Extras Sources disabled
fasttrack/7/x86_64 CentOS-7 - fasttrack disabled
updates/7/x86_64 CentOS-7 - Updates enabled: 1,348
updates-source/7 CentOS-7 - Updates Sources disabled
repolist: 24,468
[root@localhost ~]#
22 使用YUM列出禁用的存储库
使用带禁用选项的yum只列出系统上禁用的yum存储库。
[root@localhost ~]# yum repolist disabled
Loaded plugins: fastestmirror, langpacks
repo id repo name
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates
C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base
C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus
C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras
C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus
C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates
C7.2.1511-base/x86_64 CentOS-7.2.1511 - Base
C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus
C7.2.1511-extras/x86_64 CentOS-7.2.1511 - Extras
C7.2.1511-fasttrack/x86_64 CentOS-7.2.1511 - CentOSPlus
C7.2.1511-updates/x86_64 CentOS-7.2.1511 - Updates
C7.3.1611-base/x86_64 CentOS-7.3.1611 - Base
C7.3.1611-centosplus/x86_64 CentOS-7.3.1611 - CentOSPlus
C7.3.1611-extras/x86_64 CentOS-7.3.1611 - Extras
C7.3.1611-fasttrack/x86_64 CentOS-7.3.1611 - CentOSPlus
C7.3.1611-updates/x86_64 CentOS-7.3.1611 - Updates
C7.4.1708-base/x86_64 CentOS-7.4.1708 - Base
C7.4.1708-centosplus/x86_64 CentOS-7.4.1708 - CentOSPlus
C7.4.1708-extras/x86_64 CentOS-7.4.1708 - Extras
C7.4.1708-fasttrack/x86_64 CentOS-7.4.1708 - CentOSPlus
C7.4.1708-updates/x86_64 CentOS-7.4.1708 - Updates
base-debuginfo/x86_64 CentOS-7 - Debuginfo
base-source/7 CentOS-7 - Base Sources
c7-media CentOS-7 - Media
centosplus/7/x86_64 CentOS-7 - Plus
centosplus-source/7 CentOS-7 - Plus Sources
cr/7/x86_64 CentOS-7 - cr
epel-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 - Debug
epel-source/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 - Source
epel-testing/x86_64 Extra Packages for Enterprise Linux 7 - Testing - x86_64
epel-testing-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - Testing - x86_64
epel-testing-source/x86_64 Extra Packages for Enterprise Linux 7 - Testing - x86_64
extras-source/7 CentOS-7 - Extras Sources
fasttrack/7/x86_64 CentOS-7 - fasttrack
updates-source/7 CentOS-7 - Updates Sources
repolist: 0
[root@localhost ~]#
23 使用YUM启用存储库
暂时启用一个特定的存储库来安装rpm包。
例如:要安装处于禁用状态(参见第13步输出)的epel-testing存储库中的任何包,命令可能如下所示。
[root@localhost ~]# yum install unifont --enablerepo=epel-testing
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel-testing/x86_64/metalink | 8.3 kB 00:00:00
Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
epel-testing: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
epel-testing | 3.2 kB 00:00:00
(1/3): epel-testing/x86_64/updateinfo | 81 kB 00:00:00
(2/3): epel-testing/x86_64/group_gz | 88 kB 00:00:00
(3/3): epel-testing/x86_64/primary | 307 kB 00:00:00
epel-testing 1185/1185
Resolving Dependencies
--> Running transaction check
---> Package unifont.x86_64 0:10.0.07-2.el7 will be installed
--> Processing Dependency: perl(GD) for package: unifont-10.0.07-2.el7.x86_64
--> Running transaction check
---> Package perl-GD.x86_64 0:2.49-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================
Package Arch Version Repository Size
Installing:
unifont x86_64 10.0.07-2.el7 epel-testing 937 k
Installing for dependencies:
perl-GD x86_64 2.49-3.el7 base 173 k
Transaction Summary
Install 1 Package (+1 Dependent package)
Total download size: 1.1 M
Installed size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): perl-GD-2.49-3.el7.x86_64.rpm | 173 kB 00:00:00
(2/2): unifont-10.0.07-2.el7.x86_64.rpm | 937 kB 00:00:00
Total 1.8 MB/s | 1.1 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : perl-GD-2.49-3.el7.x86_64 1/2
Installing : unifont-10.0.07-2.el7.x86_64 2/2
Verifying : unifont-10.0.07-2.el7.x86_64 1/2
Verifying : perl-GD-2.49-3.el7.x86_64 2/2
Installed:
unifont.x86_64 0:10.0.07-2.el7
Dependency Installed:
perl-GD.x86_64 0:2.49-3.el7
Complete!
[root@localhost ~]#
24 使用YUM启用存储库
有时候,多个存储库具有相同的包。为了避免重复,您可以使用以下命令通过禁用所有其他存储库来启用特定存储库。
使用yum列表或yum搜索命令了解包在哪个存储库中可用。
[root@localhost ~]# yum install httpd --disablerepo=* --enablerepo=base
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
base: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-80.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos for package: httpd-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================
Package Arch Version Repository Size
Installing:
httpd x86_64 2.4.6-80.el7.centos base 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7_4.1 base 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
httpd-tools x86_64 2.4.6-80.el7.centos base 89 k
mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary
Install 1 Package (+4 Dependent packages)
Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): apr-1.4.8-3.el7_4.1.x86_64.rpm | 103 kB 00:00:00
(2/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(3/5): httpd-tools-2.4.6-80.el7.centos.x86_64.rpm | 89 kB 00:00:00
(4/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
(5/5): httpd-2.4.6-80.el7.centos.x86_64.rpm | 2.7 MB 00:00:01
Total 2.6 MB/s | 3.0 MB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7_4.1.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-80.el7.centos.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-80.el7.centos.x86_64 5/5
Verifying : httpd-tools-2.4.6-80.el7.centos.x86_64 1/5
Verifying : apr-1.4.8-3.el7_4.1.x86_64 2/5
Verifying : mailcap-2.1.41-2.el7.noarch 3/5
Verifying : httpd-2.4.6-80.el7.centos.x86_64 4/5
Verifying : apr-util-1.5.2-6.el7.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-80.el7.centos
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-80.el7.centos mailcap.noarch 0:2.1.41-2.el7
Complete!
[root@localhost ~]#
25 使用YUM列出包组
下面的命令将列出系统的可用组和环境。
[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Webmin: download.webmin.com
base: mirrors.shu.edu.cn
epel: mirrors.yun-idc.com
extras: mirrors.cn99.com
updates: mirrors.cn99.com
Installed Environment Groups:
GNOME Desktop
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Cinnamon Desktop
MATE Desktop
Basic Web Server
Virtualization Host
Server with GUI
KDE Plasma Workspaces
Development and Creative Workstation
Installed Groups:
Graphical Administration Tools
Available Groups:
Cinnamon
Compatibility Libraries
Console Internet Tools
Development Tools
Educational Software
Electronic Lab
Fedora Packager
General Purpose Desktop
Haskell
Legacy UNIX Compatibility
MATE
Milkymist
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
TurboGears application framework
Xfce
Done
[root@localhost ~]#
26 使用YUM安装包组
在组中安装包将把系统配置为特定状态。例如:如果您安装“服务器与GUI”组,那么您的系统将有一个图形桌面
yum groupinstall "Server with GUI"
27 使用YUM生成元缓存
下载并使所有元数据可用,比如包,用于当前启用的yum存储库。这个命令将帮助您更快地完成包安装。
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.1 kB 00:00:00
Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Webmin | 1.0 kB 00:00:00
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/3): extras/7/x86_64/prestodelta | 84 kB 00:00:00
(2/3): base/7/x86_64/other_db | 2.5 MB 00:00:00
(3/3): extras/7/x86_64/other_db | 120 kB 00:00:00
Webmin/other | 3.7 kB 00:00:00
Webmin 119/119
Metadata Cache Created
[root@localhost ~]#
28 使用YUM清除缓存
YUM在/var/cache/yum/目录中创建缓存,如果出现任何错误或占用了一些磁盘空间,就需要清除这个缓存。
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: Webmin base epel extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@localhost ~]#
29。YUM Shell
YUM有自己的交互式shell提示符,您可以在其中执行前面步骤中显示的所有任务。下面的示例展示了如何使用YUM shell安装包。
[root@localhost ~]# yum shell
Loaded plugins: fastestmirror, langpacks
install vsftpd
Determining fastest mirrors
epel/x86_64/metalink | 8.1 kB 00:00:00
Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Webmin | 1.0 kB 00:00:00
base | 3.6 kB 00:00:00
epel | 3.2 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/7): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/7): epel/x86_64/updateinfo | 943 kB 00:00:00
(3/7): epel/x86_64/group_gz | 88 kB 00:00:00
(4/7): extras/7/x86_64/primary_db | 187 kB 00:00:00
(5/7): epel/x86_64/primary | 3.6 MB 00:00:00
(6/7): updates/7/x86_64/primary_db | 5.2 MB 00:00:01
(7/7): base/7/x86_64/primary_db | 5.9 MB 00:00:03
Webmin/primary | 16 kB 00:00:00
Webmin 119/119
epel 12687/12687
run
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed
--> Finished Dependency Resolution
======================================================================================
Package Arch Version Repository Size
Installing:
vsftpd x86_64 3.0.2-22.el7 base 169 k
Transaction Summary
Install 1 Package
Total download size: 169 k
Installed size: 348 k
Is this ok [y/d/N]: y
Downloading packages:
vsftpd-3.0.2-22.el7.x86_64.rpm | 169 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-22.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1
Installed:
vsftpd.x86_64 0:3.0.2-22.el7
Finished Transaction
exit
Leaving Shell
[root@localhost ~]#
30 YUM帮助信息
使用以下命令获得关于YUM的更多信息。
[root@localhost ~]# yum --help
Loaded plugins: fastestmirror, langpacks
Usage: yum [options] COMMAND
List of Commands:
check Check for problems in the rpmdb
check-update Check for available package updates
clean Remove cached data
deplist List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade downgrade a package
erase Remove a package or packages from your system
fs Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.
fssnapshot Creates filesystem snapshots, or lists/deletes current snapshots.
groups Display, or use, the groups information
help Display a helpful usage message
history Display, or use, the transaction history
info Display details about a package or group of packages
install Install a package or packages on your system
langavailable Check available languages
langinfo List languages information
langinstall Install appropriate language packs for a language
langlist List installed languages
langremove Remove installed language packs for a language
list List a package or groups of packages
load-transaction load a saved transaction from filename
makecache Generate the metadata cache
provides Find what package provides the given value
reinstall reinstall a package
repo-pkgs Treat a repo. as a group of packages, so we can install/remove all of them
repolist Display the configured software repositories
search Search package details for the given string
shell Run an interactive yum shell
swap Simple way to swap packages, instead of using shell
update Update a package or packages on your system
update-minimal Works like upgrade, but goes to the 'newest' package match which fixes a problem that affects your system
updateinfo Acts on repository update information
upgrade Update packages taking obsoletes into account
version Display a version for the machine and/or available repos.
Options:
-h, --help show this help message and exit
-t, --tolerant be tolerant of errors
-C, --cacheonly run entirely from system cache, don't update cache
-c [config file], --config=[config file]
config file location
-R [minutes], --randomwait=[minutes]
maximum command wait time
-d [debug level], --debuglevel=[debug level]
debugging output level
--showduplicates show duplicates, in repos, in list/search commands
-e [error level], --errorlevel=[error level]
error output level
--rpmverbosity=[debug level name]
debugging output level for rpm
-q, --quiet quiet operation
-v, --verbose verbose operation
-y, --assumeyes answer yes for all questions
--assumeno answer no for all questions
--version show Yum version and exit
--installroot=[path] set install root
--enablerepo=[repo] enable one or more repositories (wildcards allowed)
--disablerepo=[repo] disable one or more repositories (wildcards allowed)
-x [package], --exclude=[package]
exclude package(s) by name or glob
--disableexcludes=[repo]
disable exclude from main, for a repo or for
everything
--disableincludes=[repo]
disable includepkgs for a repo or for everything
--obsoletes enable obsoletes processing during updates
--noplugins disable Yum plugins
--nogpgcheck disable gpg signature checking
--disableplugin=[plugin]
disable plugins by name
--enableplugin=[plugin]
enable plugins by name
--skip-broken skip packages with depsolving problems
--color=COLOR control whether color is used
--releasever=RELEASEVER
set value of $releasever in yum config and repo files
--downloadonly don't update, just download
--downloaddir=DLDIR specifies an alternate directory to store packages
--setopt=SETOPTS set arbitrary config and repo options
--bugfix Include bugfix relevant packages, in updates
--security Include security relevant packages, in updates
--advisory=ADVS, --advisories=ADVS
Include packages needed to fix the given advisory, in
updates
--bzs=BZS Include packages needed to fix the given BZ, in
updates
--cves=CVES Include packages needed to fix the given CVE, in
updates
--sec-severity=SEVS, --secseverity=SEVS
Include security relevant packages matching the
severity, in updates
Plugin Options:
[root@localhost ~]#

发表评论