A solution to the problem of could not get lock/var/lib/dpkg/lock in Ubuntu

Source: Internet
Author: User

Click to open the link

When Ubuntu executes the sudo apt-get install command, the following error occurs:

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?

The reason is that the apt process is still running. There are two ways to solve this problem.


Method 1: Find and kill all the apt-get and 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


Run the following command to kill apt related process

$ sudo kill-9 process ID
or
$ sudo kill-sigkill  process ID

Add: SIGKILL End/Terminate process run. The signal value is 9.


Method 2: Delete the locked file.

Once you run the apt-get or APT command, the lock file will be created in the

/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 a locked file under the/var/lib/apt/lists/,/var/cache/apt/archives/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




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.