yum 比 rpm 更加方便。yum 工具最大的优势在于可以联网去下载所需要的 rpm 包,然后自动安装。如果要安装的 rpm 包有依赖关系,yum 工具会帮我们依次安装所有相关的 rpm 包
列出所有可用的 rpm 安装包
[root@evan-01 ~]# yum list
...(省略很多内容)
zenity.x86_64 3.28.1-1.el7 base
zlib.i686 1.2.7-18.el7 base
zlib.x86_64 1.2.7-18.el7 base
zlib-devel.i686 1.2.7-18.el7 base
zlib-devel.x86_64 1.2.7-18.el7 base
zlib-static.i686 1.2.7-18.el7 base
zlib-static.x86_64 1.2.7-18.el7 base
zsh.x86_64 5.0.2-31.el7 base
zsh-html.x86_64 5.0.2-31.el7 base
zziplib.i686 0.13.62-9.el7 base
zziplib.x86_64 0.13.62-9.el7 base
zziplib-devel.i686 0.13.62-9.el7 base
zziplib-devel.x86_64 0.13.62-9.el7 base
zziplib-utils.x86_64 0.13.62-9.el7 base
[root@evan-01 ~]#
以这个为例,说下都什么含义
zziplib-utils.x86_64 0.13.62-9.el7 base
rpm 包名 | 版本信息 | 安装信息 |
---|---|---|
zziplib-utils.x86_64 | 0.13.62.9.el7 | base |
如果未安装,则显示 base 或者 anaconda;如果 rpm 包已安装但需要升级,则显示 updates
查看 yum 配置文件中的仓库
[root@evan-01 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@evan-01 ~]#
[root@evan-01 ~]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@evan-01 ~]#
搜索 rpm 包
[root@evan-01 ~]# yum search vim
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
========================================================= N/S matched: vim =========================================================
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor
Name and summary matches only, use "search all" for everything.
[root@evan-01 ~]#
可以搜到这些和 vim 相关的包,这种方法搜索的不够精准
我们可以用 grep 来过滤,从而找到相对应的 rpm 包
[root@evan-01 ~]# yum list | grep 'vim'
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
vim-common.x86_64 2:7.4.160-6.el7_6 @updates
vim-enhanced.x86_64 2:7.4.160-6.el7_6 @updates
vim-filesystem.x86_64 2:7.4.160-6.el7_6 @updates
vim-minimal.x86_64 2:7.4.160-2.el7 @anaconda
protobuf-vim.x86_64 2.5.0-8.el7 base
vim-X11.x86_64 2:7.4.160-6.el7_6 updates
vim-minimal.x86_64
[root@evan-01 ~]#
安装 rpm 包
整个过程它会首先把需要安装的 rpm 包列出来,如果有依赖关系,也会把所有依赖的包列出来。然后询问用户是否需要安装,输入 y 则安装,输入 n 则不安装。那样的话太麻烦,所以直接加上 -y选项,这样就省略了询问用户是否安装的那一步
[root@evan-01 ~]# yum install -y protobuf-vim
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package protobuf-vim.x86_64 0:2.5.0-8.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
protobuf-vim x86_64 2.5.0-8.el7 base 8.7 k
Transaction Summary
====================================================================================================================================
Install 1 Package
Total download size: 8.7 k
Installed size: 3.7 k
Downloading packages:
protobuf-vim-2.5.0-8.el7.x86_64.rpm | 8.7 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : protobuf-vim-2.5.0-8.el7.x86_64 1/1
Verifying : protobuf-vim-2.5.0-8.el7.x86_64 1/1
Installed:
protobuf-vim.x86_64 0:2.5.0-8.el7
Complete!
[root@evan-01 ~]#
卸载 rpm 包
卸载和安装一样,可以直接加上 -y 选项,从而省略与用户交互的那一步。卸载某个 rpm 包的时候一定要看清楚,不要连其他重要的 rpm 包也一起卸载了,以免影响正常的业务,所以使用 yum remove命令卸载包的时候,还是不要加 -y 选项了
[root@evan-01 ~]# yum remove protobuf-vim
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package protobuf-vim.x86_64 0:2.5.0-8.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Removing:
protobuf-vim x86_64 2.5.0-8.el7 @base 3.7 k
Transaction Summary
====================================================================================================================================
Remove 1 Package
Installed size: 3.7 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : protobuf-vim-2.5.0-8.el7.x86_64 1/1
Verifying : protobuf-vim-2.5.0-8.el7.x86_64 1/1
Removed:
protobuf-vim.x86_64 0:2.5.0-8.el7
Complete!
[root@evan-01 ~]#
升级 rpm 包
如果不加包名,会把系统中所有的 rpm 包进行升级
[root@evan-01 ~]# yum update bash
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package bash.x86_64 0:4.2.46-28.el7 will be updated
---> Package bash.x86_64 0:4.2.46-31.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Updating:
bash x86_64 4.2.46-31.el7 base 1.0 M
Transaction Summary
====================================================================================================================================
Upgrade 1 Package
Total download size: 1.0 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
bash-4.2.46-31.el7.x86_64.rpm | 1.0 MB 00:00:12
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : bash-4.2.46-31.el7.x86_64 1/2
Cleanup : bash-4.2.46-28.el7.x86_64 2/2
Verifying : bash-4.2.46-31.el7.x86_64 1/2
Verifying : bash-4.2.46-28.el7.x86_64 2/2
Updated:
bash.x86_64 0:4.2.46-31.el7
Complete!
[root@evan-01 ~]#
搜命令有哪一个包
比如你想安装 vim 的包,但是你不知道在 yum 中 vim 的包名字叫什么,那么我们就可以使用这个命令yum provides '/*/vim'
搜一下
[root@evan-01 ~]# yum provides '/*/vim'
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
base/7/x86_64/filelists_db | 7.1 MB 00:00:45
extras/7/x86_64/filelists_db | 249 kB 00:00:00
http://mirrors.aliyun.com/centos/7.6.1810/updates/x86_64/repodata/a162eee98ea1692e6a955abb497dc7a487cd7bb9408bd170165949f9776d32fe-filelists.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyun.com/centos/7.6.1810/updates/x86_64/repodata/a162eee98ea1692e6a955abb497dc7a487cd7bb9408bd170165949f9776d32fe-filelists.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
updates/7/x86_64/filelists_db | 5.2 MB 00:00:52
cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system
Repo : base
Matched from:
Filename : /usr/share/cmake/editors/vim
git-1.8.3.1-19.el7.x86_64 : Fast Version Control System
Repo : base
Matched from:
Filename : /usr/share/doc/git-1.8.3.1/contrib/vim
git-1.8.3.1-20.el7.x86_64 : Fast Version Control System
Repo : updates
Matched from:
Filename : /usr/share/doc/git-1.8.3.1/contrib/vim
2:vim-common-7.4.160-5.el7.x86_64 : The common files needed by any version of the VIM editor
Repo : base
Matched from:
Filename : /usr/share/vim
2:vim-common-7.4.160-6.el7_6.x86_64 : The common files needed by any version of the VIM editor
Repo : updates
Matched from:
Filename : /usr/share/vim
2:vim-enhanced-7.4.160-5.el7.x86_64 : A version of the VIM editor which includes recent enhancements
Repo : base
Matched from:
Filename : /usr/bin/vim
2:vim-enhanced-7.4.160-6.el7_6.x86_64 : A version of the VIM editor which includes recent enhancements
Repo : updates
Matched from:
Filename : /usr/bin/vim
2:vim-enhanced-7.4.160-6.el7_6.x86_64 : A version of the VIM editor which includes recent enhancements
Repo : @updates
Matched from:
Filename : /usr/bin/vim
[root@evan-01 ~]#