How to fix E: Could not get lock /var/lib/apt/lists/lock problem


You got following message when you try to run apt-get update command in Ubuntu?

E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

 Solution

1. Search for processes

ps -A | grep apt-get

2. See if there is any process running as apt-get then kill that process

sudo kill -9 

If the error persists, apply following commands in a termina,

sudo su
sudo rm /var/lib/apt/lists/lock
apt-get update


22 comments:

  1. This may imply that a process using apt is already underway, simply close or update your package manager (Synaptic Package Manager), if the problem persists open a terminal and type the following command:

    ReplyDelete
  2. This may imply that a process using apt is already underway, simply close or update your package manager (Synaptic Package Manager), if the problem persists open a terminal and type the following command:

    sudo rm /var/lib/dpkg/lock

    ReplyDelete
    Replies
    1. This command alone can solve the problem?

      Delete
    2. dear sir vimal i have tried the command you have given but i still encounter the same problem and i cannot install postfix on our server because of this error..

      Delete
    3. Please try this commands,
      sudo rm /var/lib/dpkg/lock
      apt-get update

      Delete
    4. Err http://archive.ubuntu.com raring/main Sources
      404 Not Found [IP: 91.189.92.200 80]

      Delete
    5. @Lalit Patil ubuntu have stopped releasing updates for ubuntu 13.04.
      Thus, I recommend you to back up your files and install either ubuntu 12.04 or ubuntu 14.04.

      Delete
  3. @Lalit Patil Same thing happened with me.!
    When I tried to figure it out, I came to know that ubuntu have stopped releasing any updates for ubuntu 13.04.
    So, try downloading ubuntu 12.04/14.04.
    Good Luck!

    ReplyDelete
    Replies
    1. Better to use Ubuntu stable releases. E.g. 12.04 LTS and 14.04 LTS.

      Delete
  4. awesome this single command saved my 2days headache!boom!

    ReplyDelete
  5. sudo rm /var/lib/dpkg/lock

    Resolved error using this above command :p)

    ReplyDelete
  6. This cmd resolves the pblm thankz

    ReplyDelete
  7. You can also use the following command

    1. Search for processes
    ps -A | grep apt-get

    2. See if there is any process running as apt-get then kill that process
    sudo kill -9

    ReplyDelete
  8. after sudo apt-get update

    am getting below error

    E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

    ReplyDelete
  9. Nooooo... Don't recommend deleting lock file... This may leave the user stranded with a broken system. This should be done only if everything else fails... By deleting a file used by system, you risk the system integrity. Don't be so fast in removing anything before trying other solutions. Before trying any solution that needs a manual modification to the system environment, reboot the system to see if the problem is solved.

    Vivek Kumar had suggested a fairly reasonable approach above. To add to his solution,

    1. Search for process
    ps aux | grep apt

    This will catch all running processes that contain apt in their name.

    2. If you see a process listed with apt-get or aptitude, kill that process as it got stuck and did not release the lock. do it with
    sudo kill

    Process-id is the process number that you identified from step 1.

    If that doesn't work, then try (like Vivek suggested)
    kill -9

    Also, note that it is not a very good idea to kill ap-get process whlie it is installing packages, do this only if your ap-get got stuck (of course, it is the subject of this post).

    In the end, if nothing above worked, you can remove the lock file at your own risk. But to reduce the risk of corrupting an installation, it is better to first close the program that's holding the lock (which in essence is covered by step #2 above). Be informed that this approach may even crash your system(but will reboot releasing the lock), this has never been my choice.
    sudo fuser -cuk /var/cache/apt/lists/lock
    sudo rm -f /var/cache/apt/lists/lock
    OR (as the case may be)
    sudo fuser -cuk /var/cache/apt/archives/lock
    sudo rm -f /var/cache/apt/archives/lock
    OR (if dpkg was stuck instead of apt)
    sudo fuser -cuk /var/lib/dpkg/lock
    sudo rm -f /var/lib/dpkg/lock

    NOTE: Use any and every command in terminal only if you understand what you are doing. Don't use sudo unless you know what you are doing. Don't use rm -f (for that matter rm command in general) if you don't know what you are doing.
    Hope this helps!

    ReplyDelete
  10. Ubuntu 13.04 is also a stable release. It's just not an LTS (long term support) which has a commitment (in general) from canonical to release updates for 5 years for server and 3 years for desktop. For all standard (non-LTS) releases, the maximum duration of support is 18 months.

    Both versions have pros and cons - LTS gets long term support and standard gets latest features. You decide which version you want. If you don't update your system very often, LTS is the way to go. I have 6 systems with a mix of both... :P

    ReplyDelete
  11. You can delete the lock file with the following command:

    sudo rm /var/lib/apt/lists/lock

    sudo rm /var/cache/apt/archives/lock

    sudo apt-get update

    ReplyDelete
  12. This Worked for me in installing Inkscape. Thank You

    ReplyDelete
  13. apt-get update
    After all above steps following lines appear,help!
    0% [Connecting to 192.168.0.3 (192.168.0.3)] [Connecting to 192.168.0.3 (192.16
    0% [Connecting to 192.168.0.3 (192.168.0.3)] [Connecting to 192.168.0.3 (192.16

    ReplyDelete