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

Source: Internet
Author: User
Tags linux mint

When using the Apt-get command or its relatively updated APT management tool in Ubuntu or its derivative versions, such as Linux Mint (which I have used as a daily work system), you may see a unable to lock on the command line Administratio N Directory (/var/lib/dpkg/) is another process using it error.

This error is especially annoying for new Linux (Ubuntu) novices who do not understand the cause of the error.

Here's an example that shows a file lock error that appears on Ubuntu 16.10:

tecmint@tecmint:~$ sudo apt install neofetch
[sudo] password for tecmint:
e:could don't get Lock/var/lib/dpkg/lock -Open (11:resource temporarily unavailable)
e:unable to lock the Administration directory (/VAR/LIB/DPKG), is Anot Her process using it?

The following output is another error that may be displayed:

E:could not get Lock/var/lib/apt/lists/lock-open (11:resource temporarily unavailable)
E:unable to lock Director y/var/lib/apt/lists/ 
e:could not get Lock/var/lib/dpkg/lock-open (11:resource temporarily unavailable) 
E:un Able to lock-administration directory (/var/lib/dpkg/), is another process using it?

How do you solve this mistake in the future? There are several ways to handle this error, but in this article we'll use two of the simplest and most effective ways to solve it. 1. Identify and kill all apt-get or apt processes

Run the following command to generate a list of all the processes that contain apt, you can use the PS and grep commands and pipe combinations to get processes that contain apt or apt-get.

$ ps-a | grep apt


You can see each apt-get or apt process in the command output above, and use the following command to kill each process.

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

$ sudo kill-9 processnumber
or
$ sudo kill-sigkill processnumber

For example, the 9 in the following command is the number of SIGKILL, which kills the first apt process:

$ sudo kill-9 13431
or
$ sudo kill-sigkill 13431
2. Delete locked Files

Locked files can block access to certain files or data in Linux systems, and this concept also exists in Windows or other operating systems.

Once you run the apt-get or APT command, the lock file will be created in/var/lib/apt/lists/,/var/lib/dpkg/,/var/cache/apt/archives/.

This helps in running apt-get or apt processes to avoid being interrupted by other users or system processes that need to use the same files. When the process completes, the locked file is deleted.

Important reminder: If you see a lock file in two different folders without seeing the Apt-get or apt process, this is because the process was killed for some reason, so you need to remove the lock file to avoid the error.

First, run the following command to remove the locked file under the/var/lib/dpkg/folder:

$ sudo rm/var/lib/dpkg/lock

Then force the reconfiguration of the package as follows:

$ sudo dpkg--configure-a

You can also delete the/var/lib/apt/lists/and the locked files under the cached folder:

$ sudo rm/var/lib/apt/lists/lock
$ sudo rm/var/cache/apt/archives/lock

Next, update your list of package sources:

$ sudo apt update
or
$ sudo apt-get update

To sum up, there are two ways to solve the problems that Ubuntu (and its derivative) users are having when using Apt-get or apt also called aptitude commands.
From:https://linux.cn/article-8040-1.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.