How to fix Unable to Lock Directory /var/lib/apt/lists/ in Ubuntu?
by Janani
Updated Mar 21, 2023
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:
2. Check the Running Processes
ps aux | grep -i apt
/usr/lib/apt/apt.systemd.daily update
root 2810 0.0 0.0 72948 4312 pts/0 S+ 15:03 0:00 sudo apt-get remove logstash
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:
/var/lib/dpkg/lock
/var/lib/dpkg/lock-frontend
/var/lib/apt/lists/lock
/var/cache/apt/archives/lock
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.
How to fix unable to lock directory /var/lib/apt/lists/ in Ubuntu - FAQs
A directory is a unique type of file that contains only the information needed to access files or other directories.
This button can be found in the lower-left corner of the screen, and may just be a Windows logo. Click the Computer or File Explorer button. In Windows 10, this looks like a folder and can be found on the left side of the menu, or in your Windows task bar at the bottom of the screen.
A file is a named collection of data that you can move around, copy, rename, or delete. Files are stored in a filesystem, a storage area on your computer's hard disk or disks. A filesystem is split into directories, which are smaller storage areas that make it easier to locate individual files.
Like a directory, a folder is a container for organizing digital data. Unlike a directory, however, it can only store files. While a directory is a hierarchical system that allows organizing data on different levels, a folder simply organizes data into one level
The term directory refers to the way a structured list of document files and folders is stored on the computer. It is comparable to a telephone directory that contains lists of names, numbers and addresses and does not contain the actual documents themselves.