The meaning of the
Could not get lockmessage is rather simple. At the time you attempt to install new software or update your operating system, there is another software installation or software upgrade underway which runs in the background and was launched on another remote or local terminal by other user with administrative privileges.
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?is that the software installation or upgrade process using either
dpkgcommand was interrupted.
The way how package management tool on Ubuntu/Debian or any other Linux operating system works is that every time package installation or update is initiated, the package management tool, in this case
dpkg, creates a lock file
var/lib/dpkg/lockto prevent concurrent execution of another software installation or update process.
In this tutorial you will learn:
- What is the most likely cause of
E: Could not get lock /var/lib/apt/lists/lockon Ubuntu Linux system
- How to avoid the
could not get lockerror message on Ubuntu Linux
- How to find process holding a lock on
- How to unlock the
- How to recover from prematurely terminated
Software Requirements and Conventions Used
|Category||Requirements, Conventions or Software Version Used|
|System||Ubuntu/Debian or any DEB based Linux Distribution|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
Could not get lock /var/lib/apt/lists/lock caused by background update processOn Ubuntu Linux systems the prevalent number of cases when the E: Could not get lock /var/lib/apt/lists/lock error message appears on Ubuntu Linux systems occurs because the package repository index update is executed automatically by the Ubuntu system itself in the background. This simply creates a lock file and prevents user to use the
dpkgtools at the same time.
The simplest and the only recommended solution is to wait and let the background package management tool update finish its work and release the lock file.
How to avoid the "could not get lock" error message on Ubuntu LinuxHaving the Ubuntu system trigger background update and preventing the user from using the
dpkgcommand can be very frustrating situation.
The solution is to stop automatic background system package list updates and run updates manually. To turn off automatic updates edit
/etc/apt/apt.conf.d/20auto-upgradesusing your favorite text editor:
$ sudo nano /etc/apt/apt.conf.d/20auto-upgradesOnce you have the file opened, switch off the
0as shown below on Line 1:
APT::Periodic::Update-Package-Lists "0"; APT::Periodic::Unattended-Upgrade "1";
How to find process and user holding a lockThe following steps can be used to identify the user and the process holding a lock preventing user to successfully execute the
- Take a note of the file lock that is being locked. For example:
E: Could not get lock /var/lib/apt/lists/lock – open (11: Resource temporarily unavailable) E: Unable to lock directory /var/lib/apt/lists/
- Use the
fusercommand to find a process ID (PID) responsible for the lock:
$ sudo fuser /var/lib/apt/lists/lock /var/lib/apt/lists/lock: 3384
- Based on the previously retrieved PID find the user and execute the command:
$ ps -p 3384 -o user,comm,args USER COMMAND COMMAND root apt apt update
How to unlock the "/var/lib/apt/lists/lock" lockIn the scenario that you are able to identify the user and the process holding a file lock as per the previous section, investigate further and see if you can let the process finish gracefully.
Do not forcefully remove lock file if there is a chance to let process finish gracefully. This my harm your system and in same cases even without the option for the recovery.
$ sudo fuser -vki /var/lib/apt/lists/lock [sudo] password for linuxconfig: USER PID ACCESS COMMAND /var/lib/apt/lists/lock: root 3384 F.... apt Kill process 3384 ? (y/N)or by using the
killcommand and previously retrieved PID eg.
$ sudo kill -9 3384In case that you killed the process manually or are unable to find the process and user holding the lock, the chances are that the previously executed software installation or software upgrade exited prematurely without giving the package management tool the chance to remove the lock.
In this scenario remove the lock file manually:
$ sudo rm /var/lib/apt/lists/lock $ sudo rm /var/lib/dpkg/lock
How to recover from prematurely terminated APT or DPKG installation processWhen the installation process is interrupted prematurely your system may be temporarily broken preventing you to perform any additional software installations resulting in an error similar to the one below:
E: Sub-process /usr/bin/dpkg returned an error code (2)Try the following commands to recover the broken DPKG system:
$ sudo dpkg --configure -a $ sudo apt install -fFor an interrupted system upgrade execute:
$ sudo apt upgrade --fix-broken