About could not get lock/var/lib/dpkg/lock solution in Ubuntu

Source: Internet
Author: User

In Ubuntu, there are times when you use sudo apt-get install to install software.

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


At this time, mainly because apt is still running, at this point the solution is


1, find and kill all the Apt-get and apt process

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

Find all the apt and apt-get processes

$ sudo kill-9 processnumber
or
$ sudo kill-sigkill processnumber
For example, 9 of the following command is the number of SIGKILL, which kills the first apt process
$ sudo kill-9 process ID
or
$ sudo kill-sigkill  process ID


2, delete the lock file

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.

When you don't see the apt-get or apt process, you see the lock file in two different folders, 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, we have solved the problem of Ubuntu (and its derivative) users using Apt-get or apt also called aptitude command [7] in two ways.

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.