• Fix "Unable to lock the administration directory (/var/lib/dpkg/)" in Ubuntu


    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.

  • 相关阅读:
    win8 64下启动Apache失败:443端口被占用的解决方法
    JavaScript初学者应注意的七个细节
    再说SQL Server数据库优化
    2010.Net程序员年终随笔
    基于Siverlight 3.0的超炫图表工具Visifire 最后一个免费版本,你还等什么?
    苦修六年 终成正果 幸福之路 从此开始
    Asp.net中服务端控件事件是如何触发的(笔记)
    我的缓存实例—工作记录
    坚持观点:决不为了用Linq而用Linq!!
    ASP.NET 之 常用类、方法的超级总结,并包含动态的EXCEL导入导出功能,奉上类库源码
  • 原文地址:https://www.cnblogs.com/stlong/p/8427866.html
Copyright © 2020-2023  润新知