RPM包管理

1
# RPM全称 RPM Package Manager 缩写,由红帽开发用于软件包的安装,升级卸载与查询

RPM包名

1
2
tree-  1.6.0  -  10        . el7      .     x86_64    .rpm
包名 版本号 发布了10次 适用于7系系统 系统架构 文件后缀

Linux中软件包类型

分类 安装 版本
rpm包(需要安装) 预先编译打包,安装简单 软件版本偏低
源码包(需要编译、安装) 手动编译打包,安装繁琐 软件版本最新
二进制包(绿色免安装软件) 解压即可使用, 安装简单 版本跟官方保持一致,不能修改源码

注意: 不管是源码包,还是rpm包,安装时都可能会有依赖关系

如何获取RPM包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1.RedHat光盘或官方网站 (通过挂载的方式访问)
[root@localhost ~]# mount /dev/cdrom /mnt mount挂载虚拟机设置镜像保持连接状态
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# ls -1 /mnt/Packages/|wc -l ls -1查看内容竖向排列
4022
df -h 可以查看挂载情况
[root@lb01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 19G 1.6G 18G 9% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 378M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt

2.RPM包官网 http://rpmfind.net/
以后报错中,libCHARSET3-samba4.so .so结尾的文件不存在,需要安装,不知道输入哪个RPM包,去RPM官网查询即可

## 各大服务的官网
mysql:https://www.mysql.com/
nginx:https://www.nginx.org/

# 各大镜像站(yum仓库,yum源):
阿里云:https://developer.aliyun.com/mirror/
网易镜像站:https://mirrors.163.com/
华为源:https://mirrors.huaweicloud.com/
清华源:https://mirrors.tuna.tsinghua.edu.cn/
中科大:https://mirrors.ustc.edu.cn/

RPM包管理

—安装RPM包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
## 语法:
rpm [选项] 安装包名
i:install 安装
v:显示安装过程
h:显示进度条


--test:检测是否能安装成功
--force:强制安装
--nodeps:忽略依赖关系

## 本地安装 需要挂载镜像进入到Packages文件里
[root@localhost Packages]# rpm -i tree-1.6.0-10.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh /mnt/Packages/unzip-6.0-19.el7.x86_64.rpm

## 远程安装
[root@localhost Packages]# rpm -i https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
[root@localhost Packages]# rpm -ivh https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
显示进度条和安装过程

查询RPM包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-q: query 查询
-qa:查询系统内所有安装过的包
-ql:查询软件包安装完后,配置文件、帮助文档、程序....的所在目录([# rpm -ql nginx)
-qc:查询软件安装后配置文件 conf配置文件 (# rpm -qc nginx)
-qf:逆向查询,根据文件名,可以查出该文件是安装了哪个RPM包 (需要完整目录)(# rpm -qf /usr/sbin/nginx)
## 这个文件/etc/redhat-release属于哪个RPM包,该包的相关信息打印出来
1.[root@localhost ~]# rpm -qi $(rpm -qf /etc/redhat-release)
2.[root@localhost ~]# rpm -qf /etc/redhat-release|xargs rpm -qi
3.[root@localhost ~]# rpm -qif /etc/redhat-release

----
## -q --scripts 查询安装时要执行的脚本
[root@localhost ~]# rpm -q --scripts nginx
----

-qi:查看已安装安装包的详细信息 (后面跟包名)
-qd:查看帮助文档位置
-qip:可以查看未安装的包详细信息 前提:得有这个包
[root@localhost ~]# rpm -qip /mnt/Packages/zip-3.0-11.el7.x86_64.rpm
-qlp:可以查看未安装的包,安装后会产生哪些文件
[root@localhost ~]# rpm -qlp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm
/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

## -q后面接包名
[root@localhost ~]# rpm -q tree // 安装过了
tree-1.6.0-10.el7.x86_64
[root@localhost ~]# rpm -q tree // 没有安装
package tree is not installed
## 过滤查询是否安装
[root@localhost ~]# rpm -qa|grep tree
tree-1.6.0-10.el7.x86_64
[root@localhost ~]# rpm -qa|grep mysql
[root@localhost ~]# rpm -qa|grep nginx
## 查看详细信息
[root@localhost ~]# rpm -qi tree
Name : tree
Version : 1.6.0
Release : 10.el7
Architecture: x86_64
Install Date: Fri 19 Apr 2024 08:05:31 PM CST
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.
## 查找安装后程序的配置文件
[root@localhost ~]# rpm -qc nginx
/etc/logrotate.d/nginx
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
/etc/nginx/fastcgi_params
/etc/nginx/fastcgi_params.default
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/mime.types.default
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
/etc/nginx/scgi_params
/etc/nginx/scgi_params.default
/etc/nginx/uwsgi_params
/etc/nginx/uwsgi_params.default
/etc/nginx/win-utf
## 逆向查询
[root@localhost ~]# rpm -qf /etc/hosts
setup-2.8.71-10.el7.noarch
[root@localhost ~]# rpm -qf /usr/sbin/ifconfig
net-tools-2.0-0.25.20131004git.el7.x86_64

卸载RPM包

1
2
## 卸载
[root@localhost ~]# rpm -e tree

升级RPM包

1
2
3
4
-U 如果老版本不存在,就全新安装,如果存在有新版即升级
-f 老版本必须存在
[root@localhost ~]# rpm -fvh tree-1.8.0-2.mga8.x86_64.rpm
[root@localhost ~]# rpm -Uvh tree-1.8.0-2.mga8.x86_64.rpm

rpm总结

1
2
3
4
5
6
7
缺陷
1.rpm包管理无法解决包与包之间的依赖关系
2.rpm包的查询,基本上都需要已经安装过的包

优点:
1.不需要网络安装
2.安装速度快