YUM安装包管理
YUM是在基于RPM的系统上使用的命令行软件包管理实用程序。
YUM-安装包管理器
YUM(最初称为Yellowdog Updater Modified)是一个命令行软件包管理器,用于基于rpm的Linux发行版。Yum最初是为了管理Red Hat Enterprise Linux系统而创建的,但是现在许多其他流行的发行版都使用此工具作为首选的命令行软件包管理器。诸如CentOS和Fedora之类的发行版都使用Yum。Yum提供了一个易于使用的界面来更新和删除软件包。百胜还处理所有依赖项和先决条件。
yum命令示例
Yum中最常用的功能是 "install", "erase", "update", "list" 和 "search"。但是,yum具有更多可以执行的功能。以下是yum的一些常见用法:
显示YUM版本
基本语法:yum --version
[root@centos01a ~]# yum --version 3.2.29 Installed: rpm-4.8.0-47.el6.x86_64 at 2015-10-25 22:23 Built : CentOS BuildSystem at 2015-07-24 11:28 Committed: Lubos Kardos at 2015-06-15 Installed: yum-3.2.29-69.el6.centos.noarch at 2015-10-25 22:24 Built : CentOS BuildSystem at 2015-07-24 10:28 Committed: Johnny Hughes at 2015-07-22 Installed: yum-plugin-fastestmirror-1.1.30-30.el6.noarch at 2015-10-25 22:24 Built : CentOS BuildSystem at 2014-10-15 07:16 Committed: Valentina Mukhamedzhanova at 2014-08-11
显示存储库-yum repolist
基本语法:yum repolist
[root@centos01a ~]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com repo id repo name status base CentOS-6 - Base 6,575 epel Extra Packages for Enterprise Linux 6 - x86_64 12,004 extras CentOS-6 - Extras 50 updates CentOS-6 - Updates 1,218 repolist: 19,847
yum安装软件包
基本语法:yum install package-name
[root@centos01a ~]# yum install htop Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com Resolving Dependencies --> Running transaction check ---> Package htop.x86_64 0:1.0.1-2.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: htop x86_64 1.0.1-2.el6 epel 75 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 75 k Installed size: 161 k Is this ok [y/N]:
如果软件包在我们的存储库中可用,则系统将提示我们回答y/N
以确认我们的操作。在这种情况下,我们将回答y
以安装名为htop
的软件包
Downloading Packages: htop-1.0.1-2.el6.x86_64.rpm | 75 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : htop-1.0.1-2.el6.x86_64 1/1 Verifying : htop-1.0.1-2.el6.x86_64 1/1 Installed: htop.x86_64 0:1.0.1-2.el6 Complete!
从上面可以看到,软件包已成功安装。
删除软件包
基本语法:yum erase package-name
或者:yum remove package-name
[root@centos01a ~]# yum erase htop Loaded plugins: fastestmirror Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package htop.x86_64 0:1.0.1-2.el6 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: htop x86_64 1.0.1-2.el6 @epel 161 k Transaction Summary ================================================================================ Remove 1 Package(s) Installed size: 161 k Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Erasing : htop-1.0.1-2.el6.x86_64 1/1 Verifying : htop-1.0.1-2.el6.x86_64 1/1 Removed: htop.x86_64 0:1.0.1-2.el6 Complete!
在此示例中,我们使用命令yum erase htop
删除了软件包htop
。您也可以使用remove
选项来获得相同的结果。
列出已安装的软件包
基本语法: yum list installed
[root@centos01a ~]# yum list installed Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com Installed Packages MAKEDEV.x86_64 3.24-6.el6 @anaconda-CentOS-201508042137.x86_64/6.7 acl.x86_64 2.2.49-6.el6 @anaconda-CentOS-201508042137.x86_64/6.7 attr.x86_64 2.4.44-7.el6 @anaconda-CentOS-201508042137.x86_64/6.7 audit.x86_64 2.3.7-5.el6 @anaconda-CentOS-201508042137.x86_64/6.7 audit-libs.x86_64 2.3.7-5.el6 @anaconda-CentOS-201508042137.x86_64/6.7 authconfig.x86_64 6.1.12-23.el6 @anaconda-CentOS-201508042137.x86_64/6.7 b43-openfwwf.noarch 5.2-10.el6 @anaconda-CentOS-201508042137.x86_64/6.7 basesystem.noarch 10.0-4.el6 @anaconda-CentOS-201508042137.x86_64/6.7 bash.x86_64 4.1.2-33.el6_7.1 @updates binutils.x86_64 2.20.51.0.2-5.43.el6
在上面的示例中,我们执行了yum list installed
命令。此命令将显示您的Linux系统上已安装的所有软件包。但是,返回的输出大小会很大。上面是此命令输出的一小部分。
列出所有软件包-yum列表
基本语法:yum list
[root@centos01a ~]# yum list Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com Installed Packages MAKEDEV.x86_64 3.24-6.el6 @anaconda-CentOS-201508042137.x86_64/6.7 acl.x86_64 2.2.49-6.el6 @anaconda-CentOS-201508042137.x86_64/6.7 attr.x86_64 2.4.44-7.el6 @anaconda-CentOS-201508042137.x86_64/6.7 audit.x86_64 2.3.7-5.el6 @anaconda-CentOS-201508042137.x86_64/6.7 audit-libs.x86_64 2.3.7-5.el6 @anaconda-CentOS-201508042137.x86_64/6.7 authconfig.x86_64 6.1.12-23.el6 @anaconda-CentOS-201508042137.x86_64/6.7 b43-openfwwf.noarch 5.2-10.el6 @anaconda-CentOS-201508042137.x86_64/6.7 basesystem.noarch
在上面的示例中,我们可以看到Installed Packages
和Available Packages
。
列出有关软件包的信息
基本语法: yum info package-name
[root@centos01a ~]# yum info htop Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com Available Packages Name : htop Arch : x86_64 Version : 1.0.1 Release : 2.el6 Size : 75 k Repo : epel Summary : Interactive process viewer URL : http://htop.sourceforge.net/ License : GPL+ Description : htop is an interactive text-mode process viewer for Linux, similar : to top(1).
检查更新
基本语法:yum check-update
可以运行yum check-update
命令来检查系统上包的任何更新。任何可用的更新都会显示出来。您也可以使用命令yum list updates
。系统可用的任何更新都会显示出来。
检查特定软件包的更新
基本语法:yum list package
[root@centos01a ~]# yum list openssl Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirrors.ukfast.co.uk * extras: repo.bigstepcloud.com * updates: mirror.ukhost4u.com Installed Packages openssl.x86_64 1.0.1e-42.el6 @anaconda-CentOS-201508042137.x86_64/6.7 Available Packages openssl.i686 1.0.1e-42.el6_7.2 updates openssl.x86_64 1.0.1e-42.el6_7.2 updates
在上面的示例中,我们正在检查名为openssl
的软件包的任何可用更新。
更新所有已安装的软件包
基本语法:yum update
[root@centos01a ~]# yum update Loaded plugins: fastestmirror Setting up Update Process Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com No Packages marked for Update
搜索安装包
基本语法:yum search pattern
[root@centos01a ~]# yum search bash Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com ============================== N/S Matched: bash =============================== bash-argsparse.noarch : An high level argument parsing library for bash bash-completion.noarch : Programmable completion for Bash bash-doc.x86_64 : Documentation files for bash bashdb.noarch : BASH debugger, the BASH symbolic debugger easybashgui.noarch : Bash function library emacs-bashdb.noarch : Bashdb support for Emacs emacs-bashdb-el.noarch : Elisp source files for Bashdb support for Emacs gromacs-bash.noarch : GROMACS bash completion bash.x86_64 : The GNU Bourne Again shell bats.noarch : Bash Automated Testing System bti.x86_64 : Bash Twitter Idiocy python-argcomplete.noarch : Bash tab completion for argparse sys_basher.x86_64 : A multithreaded hardware exerciser Name and summary matches only, use "search all" for everything.
我们搜索了包含字符串bash
的所有软件包。
yum provides
基本语法:yum provides provide-spec
显示哪个软件包提供了指定的文件。
linux中如何查看命令是由哪个软件包安装的。
[root@centos01a ~]# yum provides htop Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com htop-1.0.1-2.el6.x86_64 : Interactive process viewer Repo : epel Matched from: htop-1.0.1-2.el6.x86_64 : Interactive process viewer Repo : installed Matched from: Other : Provides-match: htop
重新安装软件包
基本语法:yum reinstall package name
yum reinstall
命令用于重新安装指定的软件包。
[root@centos01a ~]# yum reinstall htop Loaded plugins: fastestmirror Setting up Reinstall Process Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com Resolving Dependencies --> Running transaction check ---> Package htop.x86_64 0:1.0.1-2.el6 will be reinstalled --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Reinstalling: htop x86_64 1.0.1-2.el6 epel 75 k Transaction Summary ================================================================================ Reinstall 1 Package(s) Total download size: 75 k Installed size: 161 k Is this ok [y/N]: y Downloading Packages: htop-1.0.1-2.el6.x86_64.rpm | 75 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : htop-1.0.1-2.el6.x86_64 1/1 Verifying : htop-1.0.1-2.el6.x86_64 1/1 Installed: htop.x86_64 0:1.0.1-2.el6 Complete!
更新特定软件包
基本语法:yum update package name
yum update
命令用于更新特定的软件包。在使用更新选项之前,检查软件包的当前版本并检查是否有较新的版本很有用。为此,我们可以使用yum list
命令显示当前安装的版本以及任何可用的版本。
[root@centos02a ~]# yum list openssl Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirrors.ukfast.co.uk * extras: repo.bigstepcloud.com * updates: mirror.ukhost4u.com Installed Packages openssl.x86_64 1.0.1e-42.el6 @anaconda-CentOS-201508042137.x86_64/6.7 Available Packages openssl.i686 1.0.1e-42.el6_7.2 updates openssl.x86_64 1.0.1e-42.el6_7.2 updates
从上面的输出中,我们可以看到软件包openssl.x86_64
的版本为1.0.1e-42.el6
,并且有更新的版本1.0.1e-42.el6_7.2
。要更新此软件包,我们使用yum update
命令:
[root@centos02a ~]# yum update openssl.x86_64 Loaded plugins: fastestmirror Setting up Update Process Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirrors.ukfast.co.uk * extras: repo.bigstepcloud.com * updates: mirror.ukhost4u.com Resolving Dependencies --> Running transaction check ---> Package openssl.x86_64 0:1.0.1e-42.el6 will be updated ---> Package openssl.x86_64 0:1.0.1e-42.el6_7.2 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Updating: openssl x86_64 1.0.1e-42.el6_7.2 updates 1.5 M Transaction Summary ================================================================================ Upgrade 1 Package(s) Total download size: 1.5 M Is this ok [y/N]: y Downloading Packages: openssl-1.0.1e-42.el6_7.2.x86_64.rpm | 1.5 MB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Updating : openssl-1.0.1e-42.el6_7.2.x86_64 1/2 Cleanup : openssl-1.0.1e-42.el6.x86_64 2/2 Verifying : openssl-1.0.1e-42.el6_7.2.x86_64 1/2 Verifying : openssl-1.0.1e-42.el6.x86_64 2/2 Updated: openssl.x86_64 0:1.0.1e-42.el6_7.2 Complete!
降级软件包
基本语法:yum downgrade 软件包名称
如果可能,yum downgrade
命令用于将指定的软件包降级为所有已知较低版本中的最高版本。在以下示例中,我们将降级先前更新的软件包openssl.x86_64
。为了建立软件包的当前版本,我们使用了命令yum list
。
[root@centos02a ~]# yum list openssl.x86_64 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirrors.ukfast.co.uk * extras: repo.bigstepcloud.com * updates: mirror.ukhost4u.com Installed Packages openssl.x86_64 1.0.1e-42.el6_7.2 @updates [root@centos02a ~]# yum downgrade openssl.x86_64 Loaded plugins: fastestmirror Setting up Downgrade Process Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirrors.ukfast.co.uk * extras: repo.bigstepcloud.com * updates: mirror.ukhost4u.com Resolving Dependencies --> Running transaction check ---> Package openssl.x86_64 0:1.0.1e-42.el6_7.1 will be a downgrade ---> Package openssl.x86_64 0:1.0.1e-42.el6_7.2 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Downgrading: openssl x86_64 1.0.1e-42.el6_7.1 updates 1.5 M Transaction Summary ================================================================================ Downgrade 1 Package(s) Total download size: 1.5 M Is this ok [y/N]: y Downloading Packages: openssl-1.0.1e-42.el6_7.1.x86_64.rpm | 1.5 MB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : openssl-1.0.1e-42.el6_7.1.x86_64 1/2 Cleanup : openssl-1.0.1e-42.el6_7.2.x86_64 2/2 Verifying : openssl-1.0.1e-42.el6_7.1.x86_64 1/2 Verifying : openssl-1.0.1e-42.el6_7.2.x86_64 2/2 Removed: openssl.x86_64 0:1.0.1e-42.el6_7.2 Installed: openssl.x86_64 0:1.0.1e-42.el6_7.1 Complete!
使用软件包组-yum grouplist
许多软件包被分组为方便的组。这使系统管理员可以使用一个命令安装一组软件包。命令yum grouplist
可用于显示系统上的可用组。(下面是grouplist
命令的摘录)。
[root@centos01a ~]# yum grouplist Loaded plugins: fastestmirror Setting up Group Process Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com Installed Groups: E-mail server Scalable Filesystems Security Tools Storage Availability Tools iSCSI Storage Client Available Groups: Additional Development Backup Client Backup Server Base CIFS file server Client management tools Compatibility libraries Console internet tools Debugging Tools Desktop Desktop Debugging and Performance Tools Desktop Platform Desktop Platform Development Development tools Dial-up Networking Support Directory Client Directory Server Eclipse Educational Software Electronic Lab Emacs
安装一组软件包-yum groupinstall groupname
在下面的示例中,我们将安装X Window System
。要安装X Window System软件包组,我们执行命令yum groupinstall'X Window System'
。(请注意,如果组包的名称中包含空格,则必须在组名周围加上单引号。)
我们可以看到有233个软件包组成了X Window System
组。
[root@centos01a ~]# yum groupinstall 'X Window System' xorg-x11-drv-trident x86_64 1.3.6-10.el6 base 59 k xorg-x11-drv-v4l x86_64 0.2.0-36.el6 base 18 k xorg-x11-drv-vesa x86_64 2.3.2-15.el6 base 22 k xorg-x11-drv-vmmouse x86_64 13.0.0-2.el6 base 17 k xorg-x11-drv-vmware x86_64 13.0.1-9.el6 base 32 k xorg-x11-drv-void x86_64 1.4.0-23.el6 base 13 k xorg-x11-drv-voodoo x86_64 1.2.5-10.el6 base 18 k xorg-x11-drv-wacom x86_64 0.23.0-4.el6 base 258 k xorg-x11-drv-xgi x86_64 1.6.0-20.20121114git.el6 base 117 k xorg-x11-glamor x86_64 0.6.0-5.20140506gitf78901e.el6 base 103 k xorg-x11-server-common x86_64 1.15.0-36.el6.centos base 50 k xorg-x11-xkb-utils x86_64 7.7-4.el6 base 86 k xulrunner x86_64 17.0.10-1.el6.centos base 14 M yelp x86_64 2.28.1-17.el6_3 base 813 k zenity x86_64 2.28.0-1.el6 base 2.6 M Transaction Summary ================================================================================ Install 233 Package(s) Total download size: 97 M Installed size: 304 M Is this ok [y/N]: y
更新一组软件包-yum groupupdate groupname
在下面的示例中,我们将更新X Window System
组中的所有软件包。
[root@centos01a ~]# yum groupupdate 'X Window System' Loaded plugins: fastestmirror Setting up Group Process Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl
删除一组软件包-yum groupremove groupname
在下面的示例中,我们将删除一个组。要删除组X Window System
,请使用命令yum groupremove'X Window System'
。(请注意,如果组包的名称中包含空格,则必须在组名的周围加上单引号)。
[root@centos01a ~]# yum groupremove 'X Window System' Transaction Summary ================================================================================ Remove 63 Package(s) Installed size: 14 M Is this ok [y/N]:
同步所有软件包
yum distribution-synchronization
会将所有软件包升级或降级为可从任何启用的存储库获得的最新版本。
[root@centos01a ~]# yum distribution-synchronization Loaded plugins: fastestmirror Setting up Distribution Synchronization Process Loading mirror speeds from cached hostfile * base: mirrors.vooservers.com * epel: mirror.serverbeheren.nl * extras: repo.bigstepcloud.com * updates: repo.bigstepcloud.com Resolving Dependencies
显示yum记录
基本语法:yum history
yum history
命令用于显示过去发生的事务。
[root@centos01a ~]# yum history Loaded plugins: fastestmirror ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 18 | root | 2016-02-14 12:58 | Update | 1 17 | root | 2016-02-14 12:55 | Downgrade | 1 16 | root | 2016-02-14 12:54 | Erase | 63 15 | root | 2016-02-14 12:37 | Install | 233 14 | root | 2016-02-14 12:07 | Reinstall | 1
帮助-yum --help
基本语法:yum --help
通过执行yum --help
命令,您可以概览yum下可用的所有选项。您也可以使用手册页获取更多信息。
[root@centos01a ~]# yum --help Loaded plugins: fastestmirror 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 groupinfo Display details about a package group groupinstall Install the packages in a group on your system grouplist List available package groups groupremove Remove the packages in a group from your system 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 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 repolist Display the configured software repositories resolvedep Determine which package provides the given dependency search Search package details for the given string shell Run an interactive yum shell update Update a package or packages on your system 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 --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 colour 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