Linux 包管理
一、rpm 包管理
- 安装,卸载,更新(加上-v 过程,-h 显示安装百分比)
-i 安装,-e 卸载,-u 更新
[root@localhost ~]#rpm -i tree-1.6.0-10.el7.x86_64.rpm
[root@localhost ~]#rpm -e tree-1.6.0-10.el7.x86_64.rpm
[root@localhost ~]#rpm -u tree-1.6.0-10.el7.x86_64.rpm
- 查看安装包所包含的文件
查看已安装包所包含的文件
[root@localhost ~]#rpm -ql tree
/usr/bin/tree
/usr/share/doc/tree-1.6.0
/usr/share/doc/tree-1.6.0/LICENSE
/usr/share/doc/tree-1.6.0/README
/usr/share/man/man1/tree.1.gz
查看未安装包所包含的文件
rpm -qpl tree-1.6.0-10.el7.x86_64.rpm
[root@localhost ~]#rpm -qpl tree-1.6.0-10.el7.x86_64.rpm
/usr/bin/tree
/usr/share/doc/tree-1.6.0
/usr/share/doc/tree-1.6.0/LICENSE
/usr/share/doc/tree-1.6.0/README
/usr/share/man/man1/tree.1.gz
- 安装包里的文件管理
查看是否安装 包名称需要写全
[root@localhost ~]#rpm -q httpd
httpd-2.4.6-88.el7.centos.x86_64
[root@localhost ~]#
查看所有已安装的包中 http开头的
[root@localhost ~]#rpm -qa http*
httpd-2.4.6-88.el7.centos.x86_64
httpd-tools-2.4.6-88.el7.centos.x86_64
[root@localhost ~]#
查看文件属于哪个包
[root@localhost ~]#rpm -qf /etc/httpd/conf
httpd-2.4.6-88.el7.centos.x86_64
[root@localhost ~]#
- 查看包信息
[root@localhost ~]#rpm -qi tree
Name : tree
Version : 1.6.0
Release : 10.el7
Architecture: x86_64
Install Date: Fri 20 Sep 2019 10:17:56 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 ~]#
- 查看安装包的状态是否发生改变(更改,缺失,权限等)
[root@localhost ~]#which tree
/usr/bin/tree
[root@localhost ~]#mv /usr/bin/tree /data
[root@localhost ~]#rpm -V tree
missing /usr/bin/tree
[root@localhost ~]#
- 从rpm 中提取文件
查看安装包里的内容,rpm转cpio包,然后cpio -tv 查看
[root@localhost ~]#rpm2cpio tree-1.6.0-10.el7.x86_64.rpm | cpio -tv
-rwxr-xr-x 1 root root 62768 Jun 10 2014 ./usr/bin/tree
drwxr-xr-x 2 root root 0 Jun 10 2014 ./usr/share/doc/tree-1.6.0
-rw-r--r-- 1 root root 18009 Aug 13 2004 ./usr/share/doc/tree-1.6.0/LICENSE
-rw-r--r-- 1 root root 4628 Jun 24 2011 ./usr/share/doc/tree-1.6.0/README
-rw-r--r-- 1 root root 4100 Jun 24 2011 ./usr/share/man/man1/tree.1.gz
177 blocks
提取文件
[root@localhost ~]#rpm2cpio tree-1.6.0-10.el7.x86_64.rpm | cpio -idv ./usr/bin/tree
./usr/bin/tree
177 blocks
[root@localhost ~]#tree ./usr
./usr
└── bin
└── tree
1 directory, 1 file
[root@localhost ~]#
二、yum 包管理
- 配置yum 源
centos7 配置yum源
不写的话,默认是enable=1 启用 =0是禁用
默认不启用gpgkey检查
[root@localhost ~]#rm /etc/yum.repos.d/* > /dev/nul
[base]
name=CentOS-\$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
enable=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/RPM-GPG-KEY-CentOS-7
centos8 配置yum源
光盘文件有两个,所以需要两个cdrom,
centos8 gpgkey 在本地
[root@localhost ~]#rm /etc/yum.repos.d/* > /dev/nul
[root@localhost ~]#vi /etc/yum.repos.d/youyou.repo
[base]
name=CentOS-\$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/\$releasever/BaseOS/\$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[App]
name=CentOS-\$releasever - App
baseurl=http://mirrors.aliyun.com/centos/\$releasever/AppStream/\$basearch/os/
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
配置完毕后yum repolist 查看yum源列表
- yum 历史命令解释
- yum history 查看安装历史
- yum history info 12 查看12事件
- yum history undo 12 取消12的操作,如果12操作是安装,那就是卸载
- 如果12操作是卸载,那就是安装,取反
- yum clean all 清除yum 的缓存
- yum history redo 12 重新操作12步骤
- yum 搜索包
- yum search ftp 搜索关于ftp包的
- yum provides ftp 支持ftp 功能的
- yum deplist httpd 查看httpd包依赖的文件
- yum 安装卸载包
- yum install httpd 安装httpd
- yum remove htpd 卸载httpd
- yum info httpd 查看httpd包信息
- yum install a.rpm 可以解决这个包的依赖问题 并安装
- yum 包组的管理
包组管理就是 直接安装一套包组,比如 GNOME桌面等- yum groups list 查看包组
- yum groups install GNOME 安装GNOME包组
- yum groups remove 卸载安装包
- 创建yum 源的路径
- yum repolist 查看yum源列表
- createrepo /data 创建repodata 文件 ,使自定义文件夹当yum源 ,比如下面的dnf 安装包,然后把它依赖的安装包,都放在一个文件夹里,然后生成repodata,这时候这个路径就可以当做yum源,里面的.代表当前路径。
查看当前文件 [root@localhost usr]#ll total 808 -rw-r--r-- 1 root root 213696 Jun 4 2018 dnf-0.6.4-2.sdl7.noarch.rpm -rw-r--r-- 1 root root 62404 Jun 4 2018 dnf-conf-0.6.4-2.sdl7.noarch.rpm -rw-r--r-- 1 root root 75472 Jun 4 2018 libcomps-0.1.8-3.el7.x86_64.rpm -rw-r--r-- 1 root root 46792 Jun 4 2018 python2-libcomps-0.1.8-3.el7.x86_64.rpm -rw-r--r-- 1 root root 416988 Jun 4 2018 python-dnf-0.6.4-2.sdl7.noarch.rpm 生成repodata,里面的.代表当前路径 [root@localhost usr]#createrepo . Spawning worker 0 with 3 pkgs Spawning worker 1 with 2 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete 查看是否成功 [root@localhost usr]#ll total 812 -rw-r--r-- 1 root root 213696 Jun 4 2018 dnf-0.6.4-2.sdl7.noarch.rpm -rw-r--r-- 1 root root 62404 Jun 4 2018 dnf-conf-0.6.4-2.sdl7.noarch.rpm -rw-r--r-- 1 root root 75472 Jun 4 2018 libcomps-0.1.8-3.el7.x86_64.rpm -rw-r--r-- 1 root root 46792 Jun 4 2018 python2-libcomps-0.1.8-3.el7.x86_64.rpm -rw-r--r-- 1 root root 416988 Jun 4 2018 python-dnf-0.6.4-2.sdl7.noarch.rpm drwxr-xr-x 2 root root 4096 Oct 15 19:36 repodata [root@localhost usr]# [root@localhost usr]#cat /etc/yum.repos.d/CentOS-Media.repo [c7-media] name=guangpan baseurl=file:///media/ gpgcheck=1 enabled=1 gpgkey=file:///media/RPM-GPG-KEY-CentOS-7 [c7-http] name=wangluo baseurl=https://mirrors.aliyun.com/centos/7/os/$basearch/ enabled=1 [dnf] name=dnf baseurl=file:///root/usr/ enabled=1 [root@localhost usr]#yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile c7-media | 3.6 kB 00:00:00 repo id repo name status c7-http/x86_64 wangluo 10,097 c7-media guangpan 4,021 dnf dnf 5 repolist: 14,123 [root@localhost usr]#
这个时候可以看到已经可以安装了
三、centos 8 dnf包管理
- dnf和yum的区别-卸载问题
centos 7 yum 卸载 只卸载本身
可以使用 yum history undo 来撤回上次安装。
centos 8 dnf 卸载的时候 相对依赖也卸载了
在 /etc/dnf.conf clean_requirements_on_remove里可以看到这个选项
[root@CentOS8 data]#cat /etc/dnf/dnf.conf
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
[root@CentOS8 data]#
- 其余暂未发现,使用方法和yum 一样,不过dnf管理应该是比yum安装快些的。