Ubuntu dpkg Error

If you run a recent vintage of Ubuntu, you may encounter the following dpkg error when you’re trying to update or install packages. This is usually caused by Ubuntu simultaneously running another instance of the package manager, often on system startup. Still, it can be annoying when you’re trying to update your system.

root@ubuntu:/# apt-get update

Hit:1 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://security.ubuntu.com/ubuntu xenial-security InRelease       
Hit:3 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease      
Hit:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease
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?

So you remove the dpkg lock and try again, only to get another error:

root@ubuntu:/# rm /var/lib/dpkg/lock
root@ubuntu:/# apt-get update

Hit:1 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease      
Hit:3 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease    
Hit:4 http://security.ubuntu.com/ubuntu xenial-security InRelease       
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. 

The fix is to delete all the lock files and the interrupted package install:

root@ubuntu:/# sudo rm /var/lib/apt/lists/lock
root@ubuntu:/# sudo rm /var/cache/apt/archives/lock
root@ubuntu:/# cd /var/lib/dpkg/updates
root@ubuntu:/# sudo rm *
root@ubuntu:/# sudo apt-get update

Then you can run your apt-get install to complete the installation procedure.

Alternatively, here’s a simple Bash script that does the above:

#!/bin/bash
rm /var/lib/apt/lists/lock
rm var/cache/apt/archives/lock
rm /var/lib/dpkg/updates/*
apt-get update

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *