274

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
  • 114,770
GoodNite
  • 2,741
  • 2
    Perhaps reboot and try again. In my case, I tried to update using CLI command while the update was already ongoing and received the same error. – Allen King Jan 09 '22 at 18:21
  • I'm not an expert but i will tell you what worked for me. first, this website has helped me solve it. https://itsfoss.com/could-not-get-lock-error/ but another thing i did, is that i typed "sudo" before all the commands. for example; ps aux | grep -i apt > sudo ps aux | grep -i apt there are 3 solution types in this article. if it doesn't work make sure to reconfigure and update the package before. same issue happened to me when i installed tools from github which i was installing normally, however i did type sudo apt install , then sudo git clone ..., and so on. – Maie May 16 '23 at 06:32

5 Answers5

454

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,056
  • 13
    @CaTx This link will tell you what is happening behind provided solution https://itsfoss.com/could-not-get-lock-error/ – Manish Jain Sep 12 '19 at 13:32
  • 4
    In my case the machine had started just a little earlier and I got this problem. I tried again after about ten minutes (as I was looking at the situation) That time it ran ok. I vote this answer up but with a suggestion to emphasize to just try waiting before unlocking. And @Manish Jain -thanks! that reminder to gather a little info will help next time I have a similar issue! Cheers! – Peter Kelley Nov 14 '19 at 12:59
  • 1
    Some news about the UBUNTU 18 Livepatch? – Peter Krauss Dec 09 '19 at 09:43
  • Follow this for detailed: solution https://itsfoss.com/could-not-get-lock-error/, it resolved my issue as well – Sameer Kumar Choudhary Mar 18 '20 at 13:56
  • 3
    Did all of this, still getting the error. – Shayan Apr 07 '20 at 14:37
  • A case. During apt upgrade arrives an interactive choice (very strange about fileJiXDNE), and I wait to study... but lost internet connection. When back the error was there on redo apt upgrade ("heWaiting for cache lock")... Important to wait, and I do 10 minutes, but was repeating the error message 100 times, so I do ^C and start the recipe above. Even sudo killall apt apt results "apt: no process found"... So I do the next step, sudo rm ... and sudo dpkg --configure -a... Perfect! Restarts where I lost the apt process. Now I sse that fileJiXDNE is about ufw. – Peter Krauss Jun 27 '20 at 14:01
  • To add to what @PeteKelley said, running ps aux | grep -i apt showed that the system automatically started checking for updated when it was booted, hence the lock. It will look something like this /bin/sh /usr/lib/apt/apt.systemd.daily <process> where process can be update, install etc... – avn Sep 11 '20 at 07:57
  • Please remove the incorrect advice to remove the lock files, as that's a certain recipe for database corruption. :/ I added a entry in the dpkg FAQ to cover this https://wiki.debian.org/Teams/Dpkg/FAQ#Q:_What_can_be_done_when_the_dpkg_lock_is_held.3F, And we have improved both the dpkg and apt error messages to print the process currently locking the files, and apt now even waits for the lock to be released. The presence of the files does not indicate that the file is locked. – Guillem Jover Dec 25 '21 at 18:53
15

Rebooting your os can kill all the incomplete process.

try sudo reboot

Once the system rebooted, should work fine.

Sajjadur
  • 151
  • reboot worked for me as well. After rebooting I was prompted to run sudo dpkg --configure -a. All fine now and I didn't have to manually sudo rm any files. – mcExchange Mar 02 '23 at 11:04
6

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.

Tejas Lotlikar
  • 2,945
  • 5
  • 17
  • 26
  • 3
    Killing the process should be done only after the user is ABSOLUTELY sure that no other package managers are active. Else that user could easily destroy their system. The lockfile is there to protect the system -- don't disable that protection lightly. – user535733 Sep 24 '22 at 01:26
  • kill only worked with a -9 argument after it. – Tamás Sengel Oct 04 '23 at 14:05
2

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

Zanna
  • 70,465
evilReiko
  • 155
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.

  • 1
    A reboot will clear any locks held by the package manager and allow you to try your update or installation again. This is often the simplest solution, and it's safer than sudo killall apt apt-get dpkg – karel Mar 25 '24 at 07:58
  • 1
    @karel, yes indeed reboot is a better option I added more context. – Eduard Florinescu Mar 25 '24 at 08:18