分类: Linux

ubuntu 20.04系统更新或安装软件提示”下列软件包未满足的依赖关系”错误处理

【问题现象】
使用ubuntu的软件更新器进行安全更新时,提示错误如下。直接使用apt-get insall软件也出现同类提示

检查您是否使用了第三方源。如果是就禁用它们,它们常常导致问题。
然后在终端中运行以下命令:apt-get install -f
Transaction failed: 软件包系统已损坏
 下列软件包未满足的依赖关系:

libc6-dbg: Depends: libc6 (= 2.31-0ubuntu9.2) 但是 2.31-0ubuntu9.1 已经安装
libc6-dev: Depends: libc6 (= 2.31-0ubuntu9.2) 但是 2.31-0ubuntu9.1 已经安装
           Depends: libc-dev-bin (= 2.31-0ubuntu9.2) 但是 2.31-0ubuntu9.2 已经安装

【处理过程】
根据提示,运行apt-get install -f尝试修复安装

[ubuntu ~]$ sudo apt-get install -f
debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable
dpkg: 处理归档 /var/cache/apt/archives/libc6_2.31-0ubuntu9.2_amd64.deb (--unpack
)时出错:
 新的 libc6:amd64 软件包 pre-installation 脚本 子进程返回错误状态 1
在处理时有错误发生:
 /var/cache/apt/archives/libc6_2.31-0ubuntu9.2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)


下列软件包有未满足的依赖关系:
 libc6-dbg : 依赖: libc6 (= 2.31-0ubuntu9.2) 但是 2.31-0ubuntu9.1 已经安装
 libc6-dev : 依赖: libc6 (= 2.31-0ubuntu9.2) 但是 2.31-0ubuntu9.1 已经安装

先行尝试使用 dpkg -i -force-overwrite 安装指定的包,发现也提示同样错误

[ubuntu ~]$ dpkg -i -force-overwrite /var/cache/apt/archives/libc6_2.31-0ubuntu9.2_amd64.deb

debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable
dpkg: 处理归档 /var/cache/apt/archives/libc6_2.31-0ubuntu9.2_amd64.deb (--unpack
)时出错:
 新的 libc6:amd64 软件包 pre-installation 脚本 子进程返回错误状态 1
在处理时有错误发生:
 /var/cache/apt/archives/libc6_2.31-0ubuntu9.2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

这时,注意到这一句:debconf: DbDriver “config”: /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable。表示文件被其他进程锁死,才会无法继续进行安装。

那就尝试找出这进程并kill掉,释放文件占用锁死。

[ubuntu ~]$ lsof /var/cache/debconf/config.dat #会显示打开此文件的进程和PID
[ubuntu ~]$ kill -9 PID  #强制杀掉进程

但结果无法结束进程。。。

【最终解决方法】
删除/var/cache/debconf/下的所有dat文件,然后update软件源,再次运行更新安装恢复正常

[ubuntu ~]$ sudo rm -rf /var/cache/debconf/*.dat
[ubuntu ~]$ sudo apt-get update
[ubuntu ~]$ sudo apt-get install -f

Yum命令使用小记

一、查看本机已安装的软件,使用Yum list 加上 installed。若不加installed,将会列出所有源的所有软件。
若不确定名称,可加上 < | grep 软件名> 查找所有类似软件。

[root@learncloud ~]# yum list installed  #需加上installed过滤条件
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
GeoIP.x86_64                          1.5.0-14.el7                      @os      
NetworkManager.x86_64                 1:1.18.0-5.el7_7.1                @updates 
NetworkManager-libnm.x86_64           1:1.18.0-5.el7_7.1                @updates
...

[root@learncloud ~]# yum list installed | grep device #通过grep根据关键字过滤
device-mapper.x86_64                    7:1.02.158-2.el7_7.2           @updates 
device-mapper-event.x86_64              7:1.02.158-2.el7_7.2           @updates

二、查看指定软件信息,可以查看是否已安装、版本、所在源、依赖等。
使用:Yum info <软件名> 命令,再加上指定软件名称。若不加上软件名,将列出所有软件。
若不确定名称,可加上 < | grep 软件名> 查找所有类似软件。

[root@learncloud ~]# yum info docker   #查询指定软件的相关信息
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages               #可安装,也就是此软件未安装到本机
Name        : docker
Arch        : x86_64
Epoch       : 2
Version     : 1.13.1
Release     : 109.gitcccb291.el7.centos
Size        : 18 M
Repo        : extras/7/x86_64
Summary     : Automates deployment of containerized applications
URL         : https://github.com/docker/docker
License     : ASL 2.0
Description : Docker is an open-source engine that automates the deployment of any
            : application as a lightweight, portable, self-sufficient container that will
            : run virtually anywhere.
            : 
            : Docker containers can encapsulate any payload, and will run consistently on
            : and between virtually any server. The same container that a developer builds
            : and tests on a laptop will run at scale, in production*, on VMs, bare-metal
            : servers, OpenStack clusters, public instances, or combinations of the above.

[root@learncloud ~]# yum info | grep docker         #通过grep来过滤指定关键字
            :  - docker       Docker container
Name        : cockpit-docker
Name        : docker
URL         : https://github.com/docker/docker
Name        : docker-client
URL         : https://github.com/docker/docker
Name        : docker-client-latest
URL         : https://github.com/projectatomic/docker
Name        : docker-common
Summary     : Common files for docker and docker-latest
URL         : https://github.com/docker/docker
Description : This package contains the common files /usr/bin/docker which will
            : point to /usr/bin/docker-current or /usr/bin/docker-latest
            : configurable via /etc/sysconfig/docker

三、设置新的yum源,可通过yum-config-manager命令进行添加,或者复制repo文件到/etc/yum.repo.d 目录下,清除缓存后即可使用

[root@learncloud yum.repos.d]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo   #使用yum-config-manager命令,--add-repo参数添加
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo   #显示添加成功

[root@learncloud yum.repos.d]# ll
total 12
-rw-r--r-- 1 root root  614 Apr 15 17:01 CentOS-Base.repo
-rw-r--r-- 1 root root  230 Apr 15 17:01 CentOS-Epel.repo
-rw-r--r-- 1 root root 2424 Oct 19  2019 docker-ce.repo   #新增的源

四、安装软件,使用yum install 软件名,加上-y参数可以自动回答Yes交互确认步骤。

[root@learncloud ~]# yum install -y docker
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
........  #中间的输出省略                                                  

Complete!  #出现Complete提示,即完成安装
[root@learncloud ~]#

Linux常用命令(1)

记录一些Linux的常用命令,基于CentOS 7.6下

一、查看Linux版本,其实是通过使用Cat命令查看版本文件,Linux一切皆是文件!!

[root@VM_0_9_centos etc]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core) 

二、更改主机名,通过vim命令修改文件/etc/hostname来实现

[root@VM_0_9_centos etc]# vim /etc/hostname

1、进行vim后,按i进入编辑模式。
2、将文件内容修改为你所需的主机名后,按Esc键退出编辑模式。
3、输入 :(按 shift + ; 键),进入VIM的命令行模式,输入 wq,保存修改退出。


Cat、More、Less、Tail、Head命令区别简述

一、Cat
Cat命令会显示文件全部内容,同时可以对文件进行合并等操作。

二、More
More可以分页显示文件内容,并且可以进行上下翻页、显示百分比、调用VI等。

三、Less
说是最传统的Linux下的文件查看工具,可以分页显示文件,搜索、显示行号、调用IV等等。

四、Head
显示文件指定前面几行的内容,显示多少行通过参数指定。

五、Tail
显示文件指定后面几行的内容,显示多少行通过参数指定。 特定是查看日志文件时,可以使用此命令只查看后面几行新增的日志内容。