While using the apt-get command or the relatively new APT package management tool in Ubuntu Linux or its derivatives such as Linux Mint (which I actually use as my primary operating system for doing daily work), you might have encountered the error – “unable to lock the administration directory (/var/lib/dpkg/) is another process using it” on the command line.
This error can be so annoying especially for new Linux (Ubuntu) users who may not know exactly the cause of the error.
Below is an example, showing the lock file error in Ubuntu 16.04:

The output below is another possible instance of the same error:

How can you solve the above error in case you bump into it in the future? There are several ways of dealing with this error(s), but in this guide, we will go through the two easiest and probably the most effective ways of solving it.

1. Find and Kill all apt-get or apt Processes
Run the command below to generate a list of all processes whose name comprises of the word apt, you will get a list inclusive of all apt or apt-get processes by using ps and grep commands together with a pipeline.

For each apt-get or apt process that you can see in the output of the command above, kill each process using the command below.

The process ID (PID) is found in the first column from the screenshot above.

2. Delete the lock Files
A lock file simply prevents access to another file(s) or some data on your Linux system, this concept is present in Windows and other operating systems as well.

Once you run an apt-get or apt command, a lock file is created under the any of these directories /var/lib/apt/lists/, /var/lib/dpkg/ and /var/cache/apt/archives/.

This helps to avoid the apt-get or apt process that is already running from being interrupted by either a user or other system processes that would need to work with files being used by apt-get or apt. When the process has finished executing, the lock file is then deleted.

Important: In case a lock is still exiting in the two directories above with no noticeable apt-get or apt process running, this may mean the process was held for one reason or the other, therefore you need to delete the lock files in order to clear the error.

First execute the command below to remove the lock file in the /var/lib/dpkg/ directory:

Afterwards force package(s) to reconfigure like so:

Alternatively, delete the lock files in the /var/lib/apt/lists/ and cache directory as below:

Next, update your packages sources list as follows:

In conclusion, we have walked through two important methods to deal with a common problem faced by Ubuntu (and its derivatives) users, while running apt-get or apt as well as aptitude commands.
Do you have any other reliable methods to share meant for deal with this common error? Then get in touch with us via the feedback form below.
In addition, you may as well want to learn how to find and kill running processes and read through a simple guide to kill, pkill and killall commands to terminate a process in Linux.

Fix "Unable to lock the administration directory (/var/lib/dpkg/)" in Ubuntu的更多相关文章

  1. E: Unable to lock the administration directory (/var/lib/dpkg/)

    如何修复 Ubuntu 中的“Unable to lock the administration directory (/var/lib/dpkg/)” 在 Ubuntu 或者它的衍生版如 Linux ...

  2. 解决0% [Waiting for headers] 导致的unable to lock the administration directory (/var/lib/dpkg/) is another process using it

    这是我在配置vim的YouCompleteMe时遇到的问题,我需要使用CMake来编译YCM. 在我输入 $ sudo apt install cmake 由于网络原因导致安装一直卡在0% [Wait ...

  3. 解决E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

    是不是在使用ubuntu的时候特别是安装或更新的时候会出现下面的情况:  E: Could not get lock /var/lib/dpkg/lock - open (11: Resource t ...

  4. Unable to lock the administration directory (/var/lib/dpkg/),is another process using it?

    Description:无法获得锁 /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)Unable to lock the ...

  5. 修复 Ubuntu 中“Unable to lock the administration directory (/var/lib/dpkg/)”

    在 Ubuntu 或者它的衍生版如 Linux Mint(我已经作为日常工作使用的系统)中使用 apt-get 命令或者其相对更新的APT 管理工具时,你可能会在命令行中看到一个 unable to ...

  6. 解决 unable to lock the administration directory (/var/lib/dpkg/) 问题

    阿里开源镜像站提供了raspbian的软件包镜像,国内的用户可以选择改用阿里镜像站作为更新源. 但是在更换源之后,执行 sudo apt-get update && apt-get u ...

  7. E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

    E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)E: Unable to l ...

  8. E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

    sudo rm /var/lib/dpkg/locksudo dpkg --configure -a

  9. Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

    I see pretty much all the answers recommend deleting the lock. I don't recommend doing that as a fir ...

随机推荐

  1. Django框架基础知识02-路由及渲染

    1.URL(Uniform Resoure Locator)统一资源定位符是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联网上的每个文件都有一个唯一的URL ...

  2. js的闭包中关于执行环境和作用链的理解

    首先讲一讲执行环境: 执行环境按照字面上来理解就是指目前代码执行所在的环境. 当JavaScript代码执行的时候,会进入不同的执行上下文,这些执行上下文会构成了一个执行上下文栈(Execution ...

  3. UVA - 10410 Tree Reconstruction (根据dfs序和bfs序恢复一颗树)

    题意: 分析: 这题一开始完全没有思路, 一直没有找出规律. 参考了http://www.cnblogs.com/Wade-/p/6358859.html 和 http://www.cnblogs.c ...

  4. DEV Express中Bar Manager的使用

    未排版 在barManager中可以添加多种元素,如皮肤按钮,复选框等,但是下拉菜单却给出了多个冗余的控件. 遗留问题:怎么设置Bar为大图标,查找是否存在Ribbon控件. Bar 1,       ...

  5. Fiddler抓包-工具介绍(request和response)

    from:https://www.cnblogs.com/yoyoketang/p/6731121.html 本篇简单的介绍下fiddler界面的几块区域,以及各自区域到底是干什么用的,以便于各好的掌 ...

  6. HDU1412-{A} + {B},通过率并不高,但同样是用一个很简洁的函数unique,超短代码水过~

    {A} + {B} Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) http: ...

  7. [luoguP1119] 灾后重建(Floyd)

    传送门 基于Floyd的动态规划原理,我们可以只用进行一次Floyd. 而题目给出的限制条件相当于给Floyd加了时间限制而已. 还是得靠对Floyd的理解. ——代码 #include <cs ...

  8. hdu 1824 2-sat问题(判断)

    /* 题意:u,v,w队长,队员,队长留下两个队员可以回家,两个队员留下,队长回家 2-sat问题,把两个队员看成一个整体就变成一个简单2-sat问题了 */ #include<stdio.h& ...

  9. hdu 1879

    #include<stdio.h> #include<stdlib.h> #define N 100 struct node { int x,y,dis; }road[N*N] ...

  10. 我是一个线程 - IBM刘欣

    来自:码农翻身(微信号:coderising) 作者:IBM刘欣 我是一个线程,我一出生就被编了个号: 0×3704,然后被领到一个昏暗的屋子里, 这里我发现了很多和我一模一样的同伴. 我身边的同伴0 ...