yum命令
yum [options] [command] [package ...]
yum命令行选项
--nogpgcheck 禁止进行gpg check
-y 自动回答yes
-q 静默模式
--disablerepo=repoidglob 临时禁用此处的repo
--enablerepo=repoidglob 临时启用此处的repo
--noplugins 禁用所有插件
显示仓库列表
yum repolist [all|enabled|disabled]
显示程序包列表
yum list [all | glob_exp1] [glob_exp2
yum list installed [glob_exp1] [...]
yum list updates [glob_exp1] [...]
yum list available [glob_exp1] [...]
安装程序包:
yum install package1 [package2] [...]
升级程序包
yum update [package1] [package2] [...]
降级程序包
yum downgrade package1 [package2] [...]
检查可用升级
yum check-update
卸载指定程序包
remove | erase package1 [package2] [...]
查看程序包的信息
yum info package1 [package2] [...]
查看指定的特性(可以是某文件)是由那个程序包提供
yum provides | whatprovides feature1 [feature2] [...]
清理本地缓存
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
构建缓存
yum makecache
搜索程序包相关信息
yum search string1 [string2] [...]
重新安装(覆盖重新安装)
yum reinstall package1 [package2] [...]
查看指定包的依赖关系
yum deplist package1 [package2] [...]
查看yum事物历史
yum history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
包组管理的相关命令
yum groupinstall group1 [group2][...]
yum groupupdate group1 [group2][...]
yum grouplist group1 [group2][...]
yum groupremove group1 [group2][...]
yum groupinfo group1 [group2][...]
yum命令示例
列出仓库信息
[root@localhost ~]# yum repolsit
Loaded plugins: fastestmirror, langpacks
No such command: repolsit. Please use /usr/bin/yum --help
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 9,911
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,581
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 305
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 654
repolist: 23,451
安装程序
[root@localhost ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-67.el7.centos.6 will be updated
--> Processing Dependency: httpd = 2.4.6-67.el7.centos.6 for package: 1:mod_ssl-2.4.6-67.el7.centos.6.x86_64
---> Package httpd.x86_64 0:2.4.6-80.el7.centos will be an update
--> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos for package: httpd-2.4.6-80.el7.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos.6 will be updated
---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos will be an update
---> Package mod_ssl.x86_64 1:2.4.6-67.el7.centos.6 will be updated
---> Package mod_ssl.x86_64 1:2.4.6-80.el7.centos will be an update
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Updating:
httpd x86_64 2.4.6-80.el7.centos base 2.7 M
Updating for dependencies:
httpd-tools x86_64 2.4.6-80.el7.centos base 89 k
mod_ssl x86_64 1:2.4.6-80.el7.centos base 111 k
Transaction Summary
======================================================================================================================================
Upgrade 1 Package (+2 Dependent packages)
Total size: 2.9 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : httpd-tools-2.4.6-80.el7.centos.x86_64 1/6
Updating : httpd-2.4.6-80.el7.centos.x86_64 2/6
Updating : 1:mod_ssl-2.4.6-80.el7.centos.x86_64 3/6
Cleanup : 1:mod_ssl-2.4.6-67.el7.centos.6.x86_64 4/6
Cleanup : httpd-2.4.6-67.el7.centos.6.x86_64 5/6
Cleanup : httpd-tools-2.4.6-67.el7.centos.6.x86_64 6/6
Verifying : 1:mod_ssl-2.4.6-80.el7.centos.x86_64 1/6
Verifying : httpd-2.4.6-80.el7.centos.x86_64 2/6
Verifying : httpd-tools-2.4.6-80.el7.centos.x86_64 3/6
Verifying : httpd-2.4.6-67.el7.centos.6.x86_64 4/6
Verifying : 1:mod_ssl-2.4.6-67.el7.centos.6.x86_64 5/6
Verifying : httpd-tools-2.4.6-67.el7.centos.6.x86_64 6/6
Updated:
httpd.x86_64 0:2.4.6-80.el7.centos
Dependency Updated:
httpd-tools.x86_64 0:2.4.6-80.el7.centos mod_ssl.x86_64 1:2.4.6-80.el7.centos
Complete!
查看程序包信息
[root@localhost ~]# yum info httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Installed Packages
Name : httpd
Arch : x86_64
Version : 2.4.6
Release : 80.el7.centos
Size : 9.4 M
Repo : installed
From repo : base
Summary : Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
查看程序包依赖关系
[root@localhost yum.repos.d]# yum deplist zsh
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
package: zsh.x86_64 5.0.2-28.el7
dependency: /bin/sh
provider: bash.x86_64 4.2.46-30.el7
dependency: /sbin/install-info
provider: info.x86_64 5.1-5.el7
dependency: coreutils
provider: coreutils.x86_64 8.22-21.el7
dependency: grep
provider: grep.x86_64 2.20-3.el7
dependency: libc.so.6(GLIBC_2.15)(64bit)
provider: glibc.x86_64 2.17-222.el7
dependency: libdl.so.2()(64bit)
provider: glibc.x86_64 2.17-222.el7
dependency: libdl.so.2(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-222.el7
dependency: libm.so.6()(64bit)
provider: glibc.x86_64 2.17-222.el7
dependency: libm.so.6(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-222.el7
dependency: libncursesw.so.5()(64bit)
provider: ncurses-libs.x86_64 5.9-14.20130511.el7_4
dependency: librt.so.1()(64bit)
provider: glibc.x86_64 2.17-222.el7
dependency: librt.so.1(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-222.el7
dependency: libtinfo.so.5()(64bit)
provider: ncurses-libs.x86_64 5.9-14.20130511.el7_4
dependency: rtld(GNU_HASH)
provider: glibc.x86_64 2.17-222.el7
provider: glibc.i686 2.17-222.el7
查看yum事物历史
[root@localhost yum.repos.d]# yum history info
Loaded plugins: fastestmirror, langpacks
Transaction ID : 5
Begin time : Fri May 11 20:41:41 2018
Begin rpmdb : 1408:2c966990202e5fca6613cab588b093ca3fe2d932
End time : 20:41:43 2018 (2 seconds)
End rpmdb : 1409:1ef029b64fc79bfd40c9f33a48e1a7357c15adbb
User : root <root>
Return-Code : Success
Command Line : install tree
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:
Install tree-1.6.0-10.el7.x86_64 @base
history info
[root@localhost yum.repos.d]# yum history
Loaded plugins: fastestmirror, langpacks
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
5 | root <root> | 2018-05-11 20:41 | Install | 1
4 | root <root> | 2018-05-03 20:14 | Update | 1
3 | root <root> | 2018-05-03 20:04 | I, U | 25
2 | root <root> | 2018-05-03 20:02 | Install | 1
1 | System <unset> | 2018-04-30 23:41 | Install | 1387
history list
卸载程序
[root@localhost ~]# yum remove httpd
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-80.el7.centos will be erased
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: mod_wsgi-3.4-12.el7_0.x86_64
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: 1:mod_ssl-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: httpd for package: cobbler-2.8.2-1.el7.x86_64
--> Processing Dependency: httpd for package: 1:mod_ssl-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: httpd = 2.4.6-80.el7.centos for package: 1:mod_ssl-2.4.6-80.el7.centos.x86_64
--> Running transaction check
---> Package cobbler.x86_64 0:2.8.2-1.el7 will be erased
--> Processing Dependency: cobbler for package: cobbler-web-2.8.2-1.el7.noarch
---> Package mod_ssl.x86_64 1:2.4.6-80.el7.centos will be erased
---> Package mod_wsgi.x86_64 0:3.4-12.el7_0 will be erased
--> Running transaction check
---> Package cobbler-web.noarch 0:2.8.2-1.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Removing:
httpd x86_64 2.4.6-80.el7.centos @base 9.4 M
Removing for dependencies:
cobbler x86_64 2.8.2-1.el7 @epel 2.0 M
cobbler-web noarch 2.8.2-1.el7 @epel 1.5 M
mod_ssl x86_64 1:2.4.6-80.el7.centos @base 224 k
mod_wsgi x86_64 3.4-12.el7_0 @base 197 k
Transaction Summary
======================================================================================================================================
Remove 1 Package (+4 Dependent packages)
Installed size: 13 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : cobbler-web-2.8.2-1.el7.noarch 1/5
Erasing : cobbler-2.8.2-1.el7.x86_64 2/5
warning: /etc/cobbler/settings saved as /etc/cobbler/settings.rpmsave
Erasing : mod_wsgi-3.4-12.el7_0.x86_64 3/5
Erasing : 1:mod_ssl-2.4.6-80.el7.centos.x86_64 4/5
Erasing : httpd-2.4.6-80.el7.centos.x86_64 5/5
Verifying : cobbler-2.8.2-1.el7.x86_64 1/5
Verifying : mod_wsgi-3.4-12.el7_0.x86_64 2/5
Verifying : cobbler-web-2.8.2-1.el7.noarch 3/5
Verifying : 1:mod_ssl-2.4.6-80.el7.centos.x86_64 4/5
Verifying : httpd-2.4.6-80.el7.centos.x86_64 5/5
Removed:
httpd.x86_64 0:2.4.6-80.el7.centos
构建yum仓库
本地仓库
1.使用系统自带的光盘作为本地yum源,首先挂载光盘
[root@localhost dev]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
2.创建/etc/yum.repos.d/local.repo
[basename]
name=local repo
baseurl=file:///mnt
enabled=1
gpgcheck=0
3.清除并构建缓存
yum clean all
yum makecache
网络仓库
1.创建/etc/yum.repos.d/aliyum.repo
[basealiyun]
name=aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=0
3.清除并构建缓存
yum clean all
yum makecache
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: basealiyun bassename
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
basealiyun | 3.6 kB 00:00:00
bassename | 3.6 kB 00:00:00
(1/8): basealiyun/7/x86_64/group_gz | 166 kB 00:00:00
(2/8): basealiyun/7/x86_64/primary_db | 5.9 MB 00:00:02
(3/8): basealiyun/7/x86_64/filelists_db | 6.9 MB 00:00:02
(4/8): bassename/group_gz | 155 kB 00:00:00
(5/8): bassename/primary_db | 5.3 MB 00:00:00
(6/8): bassename/filelists_db | 6.2 MB 00:00:00
(7/8): basealiyun/7/x86_64/other_db | 2.5 MB 00:00:00
(8/8): bassename/other_db | 2.3 MB 00:00:00
Determining fastest mirrors
Metadata Cache Created
[root@localhost yum.repos.d]# yum repolsit
Loaded plugins: fastestmirror, langpacks
No such command: repolsit. Please use /usr/bin/yum --help
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
basealiyun/7/x86_64 aliyun 9,911
bassename local repo 9,007
repolist: 18,918
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/100818