Update locked within terminal [duplicate]

This is the terminal message I keep getting when trying to update via: sudo apt-get update

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

How can I solve it?


Solution 1:

it seems that there is some process using the lock and thats why you cant get update. to view this pending process type command

ps aux | grep apt

this will show all processes containing the word apt

now the process which is pending is one of them.

now you need to judge which is pending and kill that process by typing command

sudo kill process-number

or

sudo kill -9 process-number

this will end the process and you are ready to update

if this does not work then your sudo do not sufficient permissions. thus you need to do this process as a root. to become a root you need to set password for root and to this type command

sudo passwd

then enter your sudo password and then enter password for UNIX (root) password which will set to your root user.now type command su and then enter the unix(root) password which we set earlier and then try to update