Unable to acquire the lock /var/lib/dpkg/lock-frontend

Solved
nouveau3456 Posted messages 4 Status Membre -  
 guigui -
Hello everyone,

I have a small problem every time I try to use the command
apt-get
this message appears

E: Unable to obtain the lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to obtain the lock for dpkg (/var/lib/dpkg/lock-frontend). Another process may be using it.
root@pop-os:/home/user#

4 réponses

mamiemando Posted messages 33537 Registration date   Status Modérateur Last intervention   7 927
 
Hello,

This problem is quite classic, and a little prior research on the Internet would likely have helped you resolve your issue (see for example this page).

Problem explanation

To prevent multiple package managers from executing updates simultaneously, apt creates temporary locks and removes them once the operation is complete. This error message has two possible explanations:
  • Explanation 1: another package manager is already open,
  • Explanation 2: a package manager was abruptly closed and could not remove the locks it had set.


In your specific case, the message seems to indicate that it is

Diagnosis

To find out which case you are in, run the command
ps faux | egrep "(apt|synaptic|adept|muon|discover)"
from a terminal. This way you will see if a package manager is currently running

If lines appear, you are in case 2 (please report the result of this command to confirm). Otherwise, you are in case 1.

Problem resolution: case 1:

There is nothing to resolve; you just need to find the package manager (synaptic,
aptitude
,
apt-get
, ...). If you cannot find it, you can kill it from your process manager or with the pkill command (e.g.
sudo pkill apt-get
). You will then trigger case 2.

Problem resolution: case 2

Before running these commands, ensure that no package managers are running (see diagnosis).

1) Remove the locks until
apt-get
works. Here is a relatively exhaustive list of potential locks that might be lingering:

sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock


(there may be others)

2) You may need to complete any aborted update. Again, you will see an error message indicating that you need to run a command like:

sudo dpkg --configure -a


3) Run
apt-get
normally. For example, if you want to install
typespeed
:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install typespeed


Good luck
23
Exileur Posted messages 1621 Registration date   Status Membre Last intervention   150
 
Hello,

I'm just throwing this out there.

I recently encountered issues like this on my Ubuntu, related to a certain
python3 unattended-upgrade
that crashed and locked dpkg.

See you later.
1
guigui > Exileur Posted messages 1621 Registration date   Status Membre Last intervention  
 

Thank you, same to you!

0
mamiemando Posted messages 33537 Registration date   Status Modérateur Last intervention   7 927
 
Indeed,
unattended-upgrade
can launch automatic updates. It's an optional package that you can safely remove if it annoys you.

As I mentioned earlier, a lock should not be removed if an update is in progress, otherwise you risk messing things up.

1) You can easily check if an update is in progress by looking at the ongoing processes:

ps faux | egrep "(apt|dpkg)" | grep -v grep


If a line appears, it means an update is in progress.

2) You can then decide to abort the update. It's messy but doable. The first number that appears on this line corresponds to the PID. You can use the command
sudo kill -9 PID
by replacing PID with the appropriate value to kill said process. Go back to step (1) to check that there are no more package managers running.

3) Finally, you need to remove the residual locks, which were not removed because the package manager was abruptly killed. This includes
/var/lib/dpkg/lock
. To find the names of the implicated locks, it's very simple, just launch your package manager, for example with the command
sudo apt update
. If a lock remains, the update will not start and
apt
will give you the name of a lock, which you can then remove (
sudo rm /var/lib/dpkg/lock
). Repeat the operation until you have removed each lock.

Good luck
0
Azerty
 
Thank you
1