46

when I try to apt-get update I'm getting the below error,

E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
Scott Stensland
  • 14,755
  • 10
  • 55
  • 73
hari
  • 461
  • 1
  • 4
  • 3

2 Answers2

66

This just means that there is an application using apt.

First try to find out which application it is by using this command in the terminal

ps aux | grep '[a]pt'

If there is a process running using apt (like apt-get or aptitude), the best thing to do is just to let it finish what its doing. Otherwise you can kill it using

kill <PID of the process (2nd column in output of ps aux)>

After making sure there is no process or killing it, you can just remove the lock using

sudo rm /var/lib/apt/lists/lock
zwets
  • 11,795
  • 2
  • 32
  • 44
Fahad Yousuf
  • 1,144
  • 7
  • 12
  • 7
    drop the second pipe by adding some square brackets `ps aux | grep [a]pt` – Chris Montanaro Mar 28 '14 at 14:24
  • 1
    The trick by @shtuff.it requires quotes for me `ps aux |grep "[t]mux"` . It works by changing the `ps` `COMMAND` listing for `grep` into `grep [t]mux`, which does not match the regex `[t]mux` . Clever. – here Apr 17 '14 at 18:03
1

You can find out which process is using the file with fuser and optionally kill it:

sudo fuser -vik -TERM /var/lib/apt/lists/lock
rubo77
  • 31,573
  • 49
  • 159
  • 281
  • This type of error : Unable to lock directory could occur when there is a software update happening in parallel. Not more than one sudo code can call the root directory at the same time. – DivyaMaheswaran Dec 23 '22 at 01:30