What is unable to lock directory /var/lib/apt/lists/ error on Ubuntu?
The “unable to lock directory /var/lib/apt/lists/” error on Ubuntu typically occurs when the APT package management system is already running or has crashed. APT is a command-line tool used for managing packages on Ubuntu and other Debian-based Linux distributions.
This error message usually appears when you try to run an update or install command using APT, and it indicates that the APT system is currently locked and cannot be accessed. This can happen if another process or command is using APT, such as another update or installation command that is already running in the background.
How to fix unable to lock directory /var/lib/apt/lists/ in Ubuntu?
1. Reboot the system
You could reboot the system to fix the error. Once, you see the error, wait for some time with patience. After that, try to install your software again. Make sure that nothing is being installed, then you could reboot the machine and try again.
You can adjust the settings for automatic updates, using the below steps:
First, tap Activities and then Search.
Next, type Updates.
Now, tap the icon for Software & Updates.
Then, with the help of the checkboxes and drop-down menus choose your preferred update schedule.
2. Check the Running Processes
ps aux | grep -i apt
If there are any applications using apt, they might be shown on the list. So, see for an entry similar to:
If the daily update appears then your system is running normal updates. Then, you must wait for this process to complete, but no other action is needed. You might have another apt process that runs.
root 2810 0.0 0.0 72948 4312 pts/0 S+ 15:03 0:00 sudo apt-get remove logstash
The second column, tells the PID (process ID), and the last column shows the service that’s using apt.
Then, you may have a dpkg service that runs. To locate it, use the below command:
ps aux | grep -i dpkg
3. Provide Address to the Stuck Apt Service
When you see a mystery apt or dpkg service running, end it and check whether that resolves your error. For that, use the below command.
sudo kill 8808
Now, replace 8808 with the actual process ID (PID). It must finish and come back to a new command prompt line. If it that doesn’t happen, then just end the action by including the -9 option.
sudo kill -9 8808
4. Erase Lock Files
The error in Ubuntu may be displayed below:
These are lock files, which could prevent two instances of apt or dpkg from using the same files simultaneously.
This could occur if an installation is needed or did not finish. Just remove the lock files.
To delete or erase the lock files, use the rm command:
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
5. Reconfigure dpkg
sudo dpkg –configure -a
Cause of unable to lock directory /var/lib/apt/lists/ error on Ubuntu
The error “unable to lock directory /var/lib/apt/lists/” in Ubuntu usually occurs when another process is using the APT package management system. This could be due to one of the following reasons:
Another package manager is running: If another package manager, such as Synaptic or the Ubuntu Software Center, is running, it will lock the APT system preventing other processes from using it.
Another APT process is running: If another APT process, such as an update or upgrade process, is running in the background, it will also lock the APT system.
Insufficient permissions: If you do not have sufficient permissions to access the APT system, you may encounter this error.
Disclaimer: The above information is for general informational purposes only. All information on the Site is provided in good faith, however we make no representation or warranty of any kind, express or implied, regarding the accuracy, adequacy, validity, reliability, availability or completeness of any information on the Site.