90% of people will encounter this error when installing software on Linux. How to solve it?

Python combat community

Java combat community

Long press to identify the QR code below, add as required

Scan QR code to follow to add customer service

Enter the Python community▲

Scan QR code to follow to add customer service

Enter the Java community

Author丨Liang Xu

Source丨liangxulinux (ID: liangxulinux)

Prompt Could not get lock /var/lib/dpkg/lock report an error?

Some friends may encounter errors such as the following when using the apt package manager to update or install software:

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

or

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/apt/lists/lock – open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

Don't panic at this time, these error prompts are generally because some programs are performing certain apt operations in the background of the system, so the apt database is locked, so apt operations cannot be performed temporarily.

solution

In this case, generally we only need to wait quietly for a few minutes, or do other things first, such as browsing the articles in the Liangxu Linux official account, until the current update, installation or uninstallation task is completed, the lock It will be automatically released, and then you can perform apt operation.

Of course, the above is the correspondence under normal circumstances. Under abnormal circumstances, for example, you have waited for several minutes and the lock has not been released. You have to see if the process is stuck for some reason. Lived and kept occupying the lock. If so, then you can only kill the process and then delete the lock.

First, we first find out which process is occupying the lock file /var/lib/dpkg/lock

$ sudo lsof /var/lib/dpkg/lock

Commands corresponding to other lock files

$ sudo lsof /var/lib/dpkg/lock-frontend
$ sudo lsof /var/lib/apt/lists/lock

Then get the output result

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
unattende 1548 root 6uW REG 8,2 0 1181062 /var/lib/dpkg/lock

We can see from the result that the PID of the process is 1548

Next, kill the process

$ sudo kill -9 1548

Then you can safely delete the lock file

$ sudo rm /var/lib/dpkg/lock

or

$ sudo rm /var/lib/dpkg/lock-frontend
$ sudo rm /var/lib/apt/lists/lock

If necessary, you can also delete the lock file in the cache directory

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

After completing the above steps, remember to run the following command

$ sudo dpkg --configure -a

This problem should be solved

Finally, good luck!

程序员专栏 扫码关注填加客服 长按识别下方二维码进群

Recommended recent exciting content:  

 Comparison of programmer income in China, the United States, Japan and India

 A sad day for programmers

 SringMVC from entry to source code, this one is enough

 10 Python visual animations, carefully and beautifully


Watch the good article here to share it with more people↓↓

Guess you like

Origin blog.csdn.net/Px01Ih8/article/details/109268600