295

I'm trying to run this command in the terminal:

sudo apt install software-properties-common

This is the error message I get:

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?
karel
  • 122,292
  • 133
  • 301
  • 332
GoodNite
  • 2,951

6 Answers6

497

This may happen if

  1. 'Synaptic Package Manager' or 'Software Updater' is open.

  2. Some apt command is running in Terminal.

  3. Some apt process is running in background.

For above wait for the process to complete. If this does not happen run in terminal:

sudo killall apt apt-get

If none of the above works, remove the lock files. Run in terminal: (Note that this can seriously break your system.)

sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*

then reconfigure the packages. Run in terminal:

sudo dpkg --configure -a

and

sudo apt update

That should do the job.

Vijay
  • 8,556
20

Rebooting your os can kill all the incomplete process.

try sudo reboot

Once the system rebooted, should work fine.

Sajjadur
  • 201
  • 2
  • 2
11

Killing the process for me - for example, I got this error:

'E: Could not get lock /var/lib/apt/lists/lock. It is held by process 7913 (jammy)'

Running sudo kill 7913 worked for me.

Peter Cox
  • 111
  • 1
  • 2
5

What worked for me was to close the opened terminal or bash shell, re-open it and try again.

Zanna
  • 72,312
evilReiko
  • 185
1

This is the recommended advice from Ubuntu Teams (found here and previously posted as a comment by Guillem)

# allows you to kill the processes
sudo fuser -vki -TERM /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend

finishes pending installs

sudo dpkg --configure --pending

I followed this and it worked perfectly after a failed grub update.

From the Documentation linked above:

Removing the dpkg lock files is never a correct solution, as dpkg uses region locking (on existing files) which are bound to a process, so once the process finishes or is killed the lock is automatically released (and dpkg itself never removes the lock file). The presence of the file does not mean that the lock is currently being held, and removing them can most probably cause dpkg database or filesystem corruption. If there is ever a need to override the locks, then it is always preferable to kill an active running dpkg over ever removing the lock files, as dpkg is supposed to be resilient against abrupt system or process crashes or termination, and any issues stemming from those would be considered serious problems in need of fixing.

theYnot
  • 733
  • 5
  • 14
0

For me this works most of the times, with the caveat that any of the above solutions might break the update or upgrade process and might need fixing afterwards

sudo killall apt apt-get dpkg

The above solution should be used when a reboot is not possible, reboot will clear locks. But the above solution should be used when reboot is not an option for obvious reasons like scripts in background or other processes.