First of all we should check what process created the lock file using lsof
:
sudo lsof /var/lib/dpkg/lock
or in another situation where /var/lib/apt/lists/lock
is problematic:
sudo lsof /var/lib/apt/lists/lock
The output will be close to something like:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apt-get 12127 root 4uW REG 252,1 0 86 /var/lib/apt/lists/lock
Then we should check what the commad is doing, we can find it out using ps
, pgrep
etc; the command is apt-get
so I run:
pgrep apt-get -a
The -a
switch lists the full command for me, in my case it's:
pgrep -a apt-get
12127 apt-get update
we can see that it's running update
subcommand, I could run something like this too:
ps -f 12127
which produces:
UID PID PPID C STIME TTY STAT TIME CMD
root 12127 12126 0 09:39 pts/0 S+ 0:00 apt-get update
In this case I would wait for some minute for resource to be freed and if after 2 or 3 minute problem still exist or the command was something that I didn't care about or was not harmful for system (like this apt-get update
) I send a SIGTERM
to the process:
sudo kill -15 12127
It should do the work, If it didn't I'm going to send SIGINT
this time (It's like pressing CTRL+C):
sudo kill -2 12127
If it didn't work too, we should send an SIGHUP
(kill -1
), and finally if nothing works I simply kill the process:
sudo kill -9 12127
or
sudo pkill -9 apt-get
Then I remove busy resources:
sudo rm /var/lib/apt/lists/lock
sudo lsof /var/lib/dpkg/lock
to find the process that owns the lock file (if empty, assume the lock is left over from a previous boot and can besudo rm
d), then consider doing asudo kill -9 <PID>
(getlsof
output.sudo
. – 300D7309EF17 Dec 15 '14 at 16:55sudo pkill apt-get
worked for me. – MAChitgarha Jul 16 '18 at 05:59root <pid> <ppid> 0 15:58 ? 00:00:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install
, which seems to run apt update every time I turn the machine on. Depending on the size of the update (which often corresponds to how long ago since I used that machine the last time), this can use from 1-10 minutes to complete. After that, the lock is freed for manual apt installs and updates. Try:sudo ps aux|grep apt
or `sudo ps aux|grep unattended. – Kjetil S. Dec 15 '18 at 15:19If you are using command line, check if an application like Software Center, Software Updater, Synaptic, Gdebi is running any update/installation. If that’s the case,
If there is no such application running, please check all the open terminal windows and see if you are running an update or installing a program. If yes, wait for it to finish.If none of the above is happening, check which other process is running the apt command
– Sachin Kumar May 20 '20 at 09:20apt upgrade
just after boot. – mathandy Oct 26 '21 at 06:30