How to Fix Broken Packages in Ubuntu

By Nick Congleton – Posted on Jan 11, 2019 in Linux
 

Apt, Ubuntu’s package manager, is among the most powerful and intuitive, but that doesn’t mean that things can’t go wrong. Occasionally, a package install goes wrong on Ubuntu, and you’re left to pick up the pieces. It’s a good thing Ubuntu’s package utilities, including Apt itself, have built-in functionality to help remedy the situation and get things back to normal.

These tips and tricks should help you get unstuck in most instances. They’re all fairly universal, but every situation is different, so keep that in mind when trying to debug your own situation.

Related: How to Fix Ubuntu Update Errors

 

With Apt/Apt-Get

Apt has a couple of flags that you can use in order to fix missing dependencies or packages that broke for one reason or another during install. A common use here would be installing a third-party .deb and finding that it had dependencies you didn’t know about. Those dependencies probably won’t be pulled in on their own, and dpkg will complain that the package is missing in them. In any case, you can try these steps.

First, run an update to make sure that there aren’t newer versions of the required packages.

sudo apt update --fix-missing

Next, you can try forcing Apt to look for and correct any missing dependencies or broken packages. This will actually install any missing packages and repair existing installs.

sudo apt install -f

With DPKG

Another place where error can pop up in package installations is the configuration process. Behind the scenes, dpkg is taking care of this part, not Apt, so it would stand to reason that when a package fails during configuration, dpkg is the tool to turn to in order to fix it.

Start by trying to force dpkg to reconfigure any broken or partially configured packages.

sudo dpkg --configure -a

If that doesn’t solve the problem, you can take a more forceful approach. Start by listing any packages that dpkg marked as requiring a reinstall.

sudo dpkg -l | grep ^..r

You should see the problematic package(s) there. As long as there’s nothing that seems not to belong there, you can force-remove the broken packages.

sudo dpkg --remove --force-remove--reinstreq

When dpkg is done, try to clean up with Apt.

sudo apt clean
sudo apt update

With any luck that’ll get you back to where you started. It won’t get you the broken packages that you tried to install, but at least Apt will be functional again.

Related: Ubuntu Software Center Not Working? Here Are the Fixes

Permanent DPKG Lock

 

There’s a less common issue with ridiculous dpkg locks preventing you from doing anything. Every time you try to use Apt or dpkg, you get an error saying another application already is … when it isn’t. It’s actually easy to delete the lock file preventing you from using Apt and get back to doing what you need to. Sometimes these lock files remain in place after an error occurs in an install, derailing the process and preventing the file from being removed automatically. In this case, you’ll need to do it yourself.

sudo rm /var/lib/apt/lists/lock

For good measure, delete the lock in cache.

sudo rm /var/cache/apt/archives/lock

Conclusion

Hopefully, one of these fixes worked for you, and you’re back working on Ubuntu normally. Remember that the best way to handle a totally out-of-hand situation is to try to return to the way it was before. Don’t try to power through and add more things to solve a breakage by adding more things, unless you know exactly what you’re doing. Chances are you’ll end up with a tangled mess of broken things that’ll be harder to sort out.

Is this article useful? Yes 

How to Fix Broken Packages in Ubuntu的更多相关文章

  1. How to fix broken packages?(转)

    Try Code: sudo apt-get update to update your package list.Then Code: sudo apt-get autoclean to clean ...

  2. 解决 E: Unable to correct problems, you have held broken packages. 问题

    参考: Unable to correct problems, you have held broken packages 环境 Ubuntu 14.04, 64bit 问题 在安装gcc-4.9的时 ...

  3. ubuntu 'Unable to correct problems, you have held broken packages' 错误

    在用apt 安装软件时,有时会用国内的源以加快下载速度. 但是在使用ubuntu 14.04的过程中,这一过程可能会导致错误“Unable to correct problems, you have ...

  4. Fix catalyst driver in Ubuntu 13.04 / 13.10

    Fix catalyst driver in Ubuntu 13.04 / 13.10(墙外文章备份) 1. Introduction I found lots of people strugglin ...

  5. E: Unable to correct problems, you have held broken packages 解决方法

    在Ubuntu中安装软件的时候经常碰到E: Unable to correct problems, you have held broken packages.的错误,顾名思义是因为某些软件包冲突导致 ...

  6. E: Unable to correct problems, you have held broken packages

    问题: apt install libmysqlclient-dev Reading package lists... DoneBuilding dependency tree       Readi ...

  7. ubuntu16 安装openssh-server 一直安装不上Unable to correct problems, you have held broken packages

    zengqi@zengqi:~$ sudo apt-get install openssh-server Reading package lists... DoneBuilding dependenc ...

  8. 如何解决Ubuntu下的“E: Unable to correct problems, you have held broken packages.”的问题. aptitude

    今天安装build-essential时出现了以下问题,这属于包的依赖. 解决方案: 1,sudo apt-get install aptitude:完成aptitude命令安装 2,sudo apt ...

  9. Unable to correct problems, you have held broken packages

    Use aptitude instead of apt-get. It is more intelligent. It not only will handle downgrading conflic ...

随机推荐

  1. 别再裸奔了,你的项目代码安全吗,再不加密就out了

    在工作中,有时候我们需要部署自己的Python代码 或进行私有化部署时,尤其现在都是通过docker镜像部署,我们并不希望别人能够看到自己的Python源程序. 加密Python源代码的方式,是将.p ...

  2. matplotlib笔记3

    关于matplotlib的绘制图形的基本代码,我们可以参照下面的连接 https://matplotlib.org/gallery/index.html https://matplotlib.org/ ...

  3. 【HC89S003F4开发板】 2调度器

    HC89S003F4开发板调度器调试 一.前言 逛论坛看到有人给HC89做了调度器,调度部分直接操作堆栈的. 下载链接 下载下来调试看看. 二.用户代码 @实现效果 编译后led灯闪烁 #includ ...

  4. Mybatis动态sql及分页、特殊符号

    目的: mybatis动态sql(案例:万能查询) 查询返回结果集的处理 mybatis的分页运用 mybatis的特殊符号 mybatis动态sql(案例:万能查询) 根据id查询 模糊查询 (参数 ...

  5. NetLink通信原理研究、Netlink底层源码分析、以及基于Netlink_Connector套接字监控系统进程行为技术研究

    1. Netlink简介 0x1:基本概念 Netlink是一个灵活,高效的”内核-用户态“.”内核-内核“.”用户态-用户态“通信机制.通过将复杂的消息拷贝和消息通知机制封装在统一的socket a ...

  6. GIL与线程进程小知识点

    一 .GIL全局解释器 GIL是一个互斥锁:保证数据的安全(以牺牲效率来换取数据的安全)阻止同一个进程内多个线程同时执行(不能并行但是能够实现并发)并发:看起来像同时进行的GIL全局解释器存在的原因是 ...

  7. 3.Ubuntu/Deepin下安装Monaco/Menlo字体

    前段时间在一家公司实习,让IT给电脑安装了Ubuntu系统,用着挺好,但总感觉字体不太好看,网上小伙伴说Monaco字体不错,所以计划安装试试. 看了好多教程,不得不说,一些教程走下来真心是装不成功, ...

  8. Java集合框架介绍。Java Collection Frameworks = JCF

    Java集合框架 = Java Collection Frameworks  = JCF . 为了方便理解,我画了一张思维脑图.

  9. Vue-filter指令全局过滤和稀有过滤

    简单介绍一下过滤器,顾名思义,过滤就是一个数据经过了这个过滤之后出来另一样东西,可以是从中取得你想要的,或者给那个数据添加点什么装饰,那么过滤器则是过滤的工具.例如,从['abc','abd','ad ...

  10. [ipsec][strongswan] strongswan源码分析--(四)plugin加载优先级原理

    前言 如前所述, 我们知道,strongswan以插件功能来提供各种各样的功能.插件之间彼此相互提供功能,同时也有可能提供重复的功能. 这个时候,便需要一个优先级关系,来保证先后加载顺序. 方法 在配 ...