linux下删除或卸载已安装的rpm包的方法

发布时间:2021-01-06编辑:脚本学堂
工作中有时你想删除或卸载已安装好的软件。但可能只知道这个软件安装好后的文件名是什么,此时可以先用which或其find找到你想删除的文件。

工作中有时你想删除或卸载已安装好的软件。但可能只知道这个软件安装好后的文件名是什么,此时可以先用which或其find找到你想删除的文件。

[root@localhost rpm]# which httpd  ---查删除的文件
/usr/sbin/httpd

[root@localhost rpm]# rpm -q -f /usr/sbin/httpd  --根据文件查出所对应的rpm包名
httpd-2.2.3-31.el5.centos

[root@localhost rpm]# rpm -e httpd-2.2.3-31.el5.centos  --执行删除
error: Failed dependencies: --会报错,这说明会有依赖关系存在
        httpd-mmn = 20051115 is needed by (installed) php-5.1.6-23.2.el5_3.i386
        httpd-mmn = 20051115 is needed by (installed) mod_python-3.2.8-3.1.i386
        httpd-mmn = 20051115 is needed by (installed) mod_ssl-2.2.3-31.el5.centos.i386
        httpd-mmn = 20051115 is needed by (installed) mod_perl-2.0.4-6.el5.i386
        webserver is needed by (installed) webalizer-2.01_10-30.1.i386
        httpd is needed by (installed) piranha-0.8.4-13.el5.i386
        httpd >= 2.0.40 is needed by (installed) mod_python-3.2.8-3.1.i386
        httpd = 0:2.2.3-31.el5.centos is needed by (installed) mod_ssl-2.2.3-31.el5.centos.i386
        httpd = 2.2.3-31.el5.centos is needed by (installed) httpd-manual-2.2.3-31.el5.centos.i386
        httpd >= 2.2.0 is needed by (installed) gnome-user-share-0.10-6.el5.i386
        httpd is needed by (installed) system-config-httpd-1.3.3.3-1.el5.noarch

[root@localhost rpm]# rpm -e --allmatches httpd-2.2.3-31.el5.centos
error: Failed dependencies:
        httpd-mmn = 20051115 is needed by (installed) php-5.1.6-23.2.el5_3.i386
        httpd-mmn = 20051115 is needed by (installed) mod_python-3.2.8-3.1.i386
        httpd-mmn = 20051115 is needed by (installed) mod_ssl-2.2.3-31.el5.centos.i386
        httpd-mmn = 20051115 is needed by (installed) mod_perl-2.0.4-6.el5.i386
        webserver is needed by (installed) webalizer-2.01_10-30.1.i386
        httpd is needed by (installed) piranha-0.8.4-13.el5.i386
        httpd >= 2.0.40 is needed by (installed) mod_python-3.2.8-3.1.i386
        httpd = 0:2.2.3-31.el5.centos is needed by (installed) mod_ssl-2.2.3-31.el5.centos.i386
        httpd = 2.2.3-31.el5.centos is needed by (installed) httpd-manual-2.2.3-31.el5.centos.i386
        httpd >= 2.2.0 is needed by (installed) gnome-user-share-0.10-6.el5.i386
        httpd is needed by (installed) system-config-httpd-1.3.3.3-1.el5.noarch

-----加上删除一些选项,--allmatches是把与这个rpm包所有相匹配的rpm包全部删除掉;--nodeps是在删除时不进行依赖性的读取
[root@localhost rpm]# rpm -e --allmatches --nodeps httpd-2.2.3-31.el5.centos
[root@localhost rpm]# which httpd  ---再次查询,已经安装的rpm包已经没有了