Wednesday, October 24, 2012

How to fix “Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)” error in Ubuntu

Somtimes it is just impossible to update your machine running Ubuntu. Recently I too faced the same issue. The error was as shown below.

$ sudo apt-get update
[sudo] password for baban:
E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

As you can see the reason is quite obvious from the error itself. It means that another process is already using the mentioned directory which is necessary to install the application through any of the installation methods (like Synaptic Pacakge Manager, Update Manager, Ubuntu Software Center or it may be simply through terminal). So first we need to make sure that the 'Synaptic Package Manager' is not open. And if it is not then find out which application is being updated or installed and wait for it to finish. In case we need to find the process that is using that particular file, you can run the below mentioned command.

$ sudo fuser -vki /var/lib/apt/lists/lock

Or we can go directly for the below mentioned command to kill all the processes related to package updation.

$ sudo killall apt-get apt aptitude adept synaptic

Now if all the above solutions do not work which unfortunately was my case, we can run the below command finally to get rid of the error.

$ sudo rm /var/lib/apt/lists/* -vf

As you can see that I had removed all the locks that synaptic had acquired. After which I could run update successfully. It is not an ideal solution but worked perfectly for me and so will for you too.

1 comment: