RPM包管理
RPM包概述
什么是rpm包
- 由红帽开发的软件 升级、安装、卸载、查询 工具
为什么要使用rpm
- 就像在windows系统中一样,如果你想要安装一个QQ,安装一个微信,安装一款游戏,首先要去该软件的官网上去
下载相关的软件包,通常都是.exe的安装包。还有那种绿色软件包,一下载下来,解压开就能使用无需安装。 那么Linux中也有很多种类的安装包,我们在Linux上也需要安装软件,软件包的种类也有很多,但是最方便,最简 单,最简易,速度最快的,也就是rpm包了。
rpm包命名规则
## tree-1.6.0-10.el7.x86_64.rpm
tree:软件名称
1.6.0:版本号
10:该版本的发布次数
el7:适用系统版本(RedHat7,CentOS7)向下兼容
x86_64:系统平台 64 x86:32位 i386
rpm:包后缀名
Linux中软件的安装方式
安装 | 版本 | |
rpm安装 | 已经编译好的源码包,下载下来后,直接使用rpm命令安装即可 | 版本会低于官方版本 |
源码安装 | 先编译,将源代码翻译成系统认识的软件,再安装 | 步骤复杂繁琐 |
二进制安装 | 绿色软件(免安装) | 不是所有程序都有二进制包 |
RPM包获取途径
- 系统光盘镜像/CentOS官网:TP
1.检查光盘是否放入光驱。
# 挂载语法
0 ✓ 00:47:22 root@leidage,10.0.0.100:<sub> # mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
# 查看磁盘信息
df -h 查看磁盘分区情况,磁盘使用情况,也能查看到挂载设备及目录
0 ✓ 00:47:45 root@leidage,10.0.0.100:</sub> # df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda3 19G 1.7G 17G 9% /
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.4G 4.4G 0 100% /mnt
# 卸载语法
umount 目标路径
0 ✓ 01:06:47 root@leidage,10.0.0.100:<sub> # umount /mnt
# 卸载报错
[root@localhost mnt]# umount /mnt
umount: /mnt: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
因为光盘没有连接,所以报错!
[root@localhost mnt]# cd
[root@localhost </sub>]# umount /mnt
原因:设备繁忙!
# 查看挂载结果
0 ✓ 00:47:22 root@leidage,10.0.0.100:<sub> # mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
0 ✓ 01:07:38 root@leidage,10.0.0.100:</sub> # ll /mnt
total 696
-rw-r--r-- 3 root root 14 Oct 30 2020 CentOS_BuildTag
drwxr-xr-x 3 root root 2048 Oct 27 2020 EFI
-rw-rw-r-- 21 root root 227 Aug 30 2017 EULA
-rw-rw-r-- 21 root root 18009 Dec 10 2015 GPL
drwxr-xr-x 3 root root 2048 Oct 27 2020 images
drwxr-xr-x 2 root root 2048 Nov 3 2020 isolinux
drwxr-xr-x 2 root root 2048 Oct 27 2020 LiveOS
drwxr-xr-x 2 root root 673792 Nov 4 2020 Packages
drwxr-xr-x 2 root root 4096 Nov 4 2020 repodata
-rw-rw-r-- 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root 2883 Nov 4 2020 TRANS.TBL
0 ✓ 01:12:06 root@leidage,10.0.0.100:~ # ll /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
-rw-rw-r-- 3 root root 47508 Jul 4 2014 /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
- RPM包查询官方网站:TP
- 其他软件官方网站
rpm命令使用-安装
# 语法:
rpm [选项] rpm包名
#rpm包名:
- 本地包名:在系统中某个目录下的rpm包
- 远程包名:不用下载,直接使用网站上的rpm包
# 选项:
-i:安装
-v:显示安装的过程
-h:显示安装的进度条
--test:仅测试,不安装
--force:强制安装
--nodeps:忽略依赖关系
# 举例 -i
0 ✓ 01:13:25 root@leidage,10.0.0.100:<sub> # rpm -i /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
# 举例 -v
0 ✓ 01:19:46 root@leidage,10.0.0.100:</sub> # rpm -vi /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing packages...
tree-1.6.0-10.el7.x86_64
# 举例 -h
0 ✓ 01:19:46 root@leidage,10.0.0.100:<sub> # rpm -ivh /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:tree-1.6.0-10.el7 ################################# [100%]
# 举例 --test
0 ✓ 01:27:03 root@leidage,10.0.0.100:</sub> # rpm -ivh --test /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing... ################################# [100%]
# 举例 --force --nodeps
0 ✓ 01:27:03 root@leidage,10.0.0.100:<sub> # rpm -ivh --force --nodeps samba-4.8.3-4.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:samba-0:4.8.3-4.el7 ################################# [100%]
#举例:远程
0 ✓ 01:27:03 root@leidage,10.0.0.100:</sub> # rpm -ivh https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/zip-3.0-11.el7.x86_64.rpm
# 注意:rpm命令管理rpm包的缺点,无法解决依赖关系
rpm命令使用-查询
# 语法
rpm [选项] rpm包名
# 选项
-q:查看指定的安装包是否安装
--- 以下选项皆要配合-q使用 ---
-a:全部安装过的包
-i:详细信息
-l:列出rpm包相关的配置文件和目录
-c:只查看该软件包相关的配置文件
-d:只查看该软件的帮助文档文件
-f:反向查找,根据配置文件,目录,帮助文档,查找该文件属于哪个包
--scripts:查看安装包,安装之前之后,和卸载之前之后要执行的脚本
--- 和上面选项配合使用 ---
-p:查询未安装的包相关信息
-qip:查看没有安装包的详细信息(指定一个已存在的完整包名或者远程包名)
-qlp:查看没有安装包会生成那些文件(指定一个已存在的完整包名或者远程包名)
-qcp:查看没有安装包会生成哪些配置文件(指定一个已存在的完整包名或者远程包名)
-qdp:查看没有安装包会生成哪些帮助文件(指定一个已存在的完整包名或者远程包名)
# 举例 -q
0 ✓ 01:28:49 root@leidage,10.0.0.100:<sub> # rpm -q vim-common
vim-common-7.4.629-8.el7_9.x86_64
# 举例 -q -a
0 ✓ 01:35:03 root@leidage,10.0.0.100:</sub> # rpm -qa
NetworkManager-team-1.18.8-1.el7.x86_64
grub2-common-2.02-0.86.el7.centos.noarch
NetworkManager-tui-1.18.8-1.el7.x86_64
setup-2.8.71-11.el7.noarch
grub2-2.02-0.86.el7.centos.x86_64
basesystem-10.0-7.el7.centos.noarch
openssh-server-7.4p1-21.el7.x86_64
0 ✓ 01:36:44 root@leidage,10.0.0.100:<sub> # rpm -qa|grep 'net'
libnfnetlink-1.0.1-4.el7.x86_64
libnetfilter_conntrack-1.0.6-1.el7_3.x86_64
net-tools-2.0-0.25.20131004git.el7.x86_64
dracut-network-033-572.el7.x86_64
# 举例 -q -i 命令组合使用
0 ✓ 01:37:04 root@leidage,10.0.0.100:</sub> # rpm -qa|grep 'net'|xargs rpm -qi
Description :
libnetfilter_conntrack is a userspace library providing a programming
interface (API) to the in-kernel connection tracking state table.
Name : net-tools
Version : 2.0
Release : 0.25.20131004git.el7
Architecture: x86_64
Install Date: Sat 26 Mar 2022 10:52:48 PM CST
Group : System Environment/Base
Size : 938978
License : GPLv2+
Signature : RSA/SHA256, Fri 23 Aug 2019 05:36:04 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : net-tools-2.0-0.25.20131004git.el7.src.rpm
Build Date : Fri 09 Aug 2019 09:10:26 AM CST
Build Host : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://sourceforge.net/projects/net-tools/
Summary : Basic networking tools
[root@localhost Packages]# rpm -qi `rpm -qa|grep 'net'`
[root@localhost Packages]# rpm -qi $(rpm -qa|grep 'net')
# 举例 -q -l
0 ✓ 01:40:28 root@leidage,10.0.0.100:<sub> # rpm -ql zip
/usr/bin/zip
/usr/bin/zipcloak
/usr/bin/zipnote
/usr/bin/zipsplit
/usr/share/doc/zip-3.0
/usr/share/doc/zip-3.0/CHANGES
/usr/share/doc/zip-3.0/LICENSE
/usr/share/doc/zip-3.0/README
/usr/share/doc/zip-3.0/README.CR
/usr/share/doc/zip-3.0/TODO
/usr/share/doc/zip-3.0/WHATSNEW
/usr/share/doc/zip-3.0/WHERE
/usr/share/doc/zip-3.0/algorith.txt
/usr/share/man/man1/zip.1.gz
/usr/share/man/man1/zipcloak.1.gz
/usr/share/man/man1/zipnote.1.gz
/usr/share/man/man1/zipsplit.1.gz
# 举例 -q -c
0 ✓ 01:40:35 root@leidage,10.0.0.100:</sub> # rpm -qc zip
#举例 -q -d
0 ✓ 01:41:26 root@leidage,10.0.0.100:<sub> # rpm -qd zip
/usr/share/doc/zip-3.0/CHANGES
/usr/share/doc/zip-3.0/LICENSE
/usr/share/doc/zip-3.0/README
/usr/share/doc/zip-3.0/README.CR
/usr/share/doc/zip-3.0/TODO
/usr/share/doc/zip-3.0/WHATSNEW
/usr/share/doc/zip-3.0/WHERE
/usr/share/doc/zip-3.0/algorith.txt
/usr/share/man/man1/zip.1.gz
/usr/share/man/man1/zipcloak.1.gz
/usr/share/man/man1/zipnote.1.gz
/usr/share/man/man1/zipsplit.1.gz
#举例 -q -f
0 ✓ 01:46:01 root@leidage,10.0.0.100:</sub> # rpm -qf /etc/yum
yum-3.4.3-168.el7.centos.noarch
#举例:-qip
0 ✓ 01:44:22 root@leidage,10.0.0.100:~ # rpm -qip /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Name : tree
Version : 1.6.0
Release : 10.el7
Architecture: x86_64
Install Date: (not installed)
Group : Applications/File
Size : 89505
License : GPLv2+
Signature : RSA/SHA256, Fri 04 Jul 2014 01:36:46 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : tree-1.6.0-10.el7.src.rpm
Build Date : Tue 10 Jun 2014 03:28:53 AM CST
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://mama.indstate.edu/users/ice/tree/
Summary : File system tree viewer
Description :
The tree utility recursively displays the contents of directories in a
tree-like format. Tree is basically a UNIX port of the DOS tree
utility.
rpm命令使用-升级
# 选项
-U:update升级,如果老版本不存在,则安装,如果老版本存在则升级
-f:必须有老版本存在
# 查询当前系统中安装nginx的包(1.10版本)
0 ✓ 01:44:53 root@leidage,10.0.0.100:<sub> # rpm -qa|grep nginx
nginx-1.10.0-1.el7.ngx.x86_64
# 使用ivh安装nginx 1.12版本的包
0 ✓ 02:07:02 root@leidage,10.0.0.100:</sub> # rpm -ivh nginx-1.12.0-1.el7.ngx.x86_64.rpm
# 报错如下:因为系统中已存在1.10版本的nginx所以无法使用ivh安装
warning: nginx-1.12.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing... ################################# [100%]
file /etc/logrotate.d/nginx from install of nginx-1:1.12.0-1.el7.ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/sbin/nginx from install of nginx-1:1.12.0-1.el7.ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/sbin/nginx-debug from install of nginx-1:1.12.0-1.el7.ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/lib/systemd/system/nginx.service from install of nginx-1:1.12.0-1.el7.ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/libexec/initscripts/legacy-actions/nginx/upgrade from install of nginx-1:1.12.0-1.el7.ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
# 使用Uvh安装,会将已存在的老版本卸载,升级成新1.12版本
1 ✗ 02:07:44 root@leidage,10.0.0.100:<sub> # rpm -Uvh nginx-1.12.0-1.el7.ngx.x86_64.rpm
warning: nginx-1.12.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:nginx-1:1.12.0-1.el7.ngx ################################# [ 50%]
Cleaning up / removing...
2:nginx-1:1.10.0-1.el7.ngx ################################# [100%]
# 查看当前系统中的nginx版本为升级后的1.12版本
1 ✗ 02:08:56 root@leidage,10.0.0.100:</sub> # rpm -qa | grep nginx
nginx-1.12.0-1.el7.ngx.x86_64
rpm命令使用-卸载
# 选项
-e:后面接卸载的包名即可
#举例:
0 ✓ 02:10:35 root@leidage,10.0.0.100:<sub> # rpm
0 ✓ 02:11:08 root@leidage,10.0.0.100:</sub> # rpm -qa |grep nginx
0 ✓ 02:12:09 root@leidage,10.0.0.100:<sub> # rpm -qa|grep mariadb
mariadb-server-5.5.68-1.el7.x86_64
mariadb-5.5.68-1.el7.x86_64
mariadb-libs-5.5.68-1.el7.x86_64
0 ✓ 02:12:27 root@leidage,10.0.0.100:</sub> # rpm -e $(rpm -qa|grep mariadb)
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-6.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-6.el7.x86_64
3 ✗ 02:12:48 root@leidage,10.0.0.100:~ #
镜像站地址
1.阿里云镜像站:http://mirrors.aliyun.com
2.网易镜像站: http://mirrors.163.com/
3.清华源:https://mirrors.tuna.tsinghua.edu.cn
4.中科大源:https://mirrors.ustc.edu.cn/