Repository errors are a common issue on debian based systems. In Kali Linux you will face the mentioned exception when trying to install some packages with apt-get
:
E: Could not get lock /var/lib/apt/lists/lock – open (9: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not get lock /var/lib/dpkg/lock – open (9: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
The issue is basically caused by the lock files. Lock files are used to prevent two or more processes from using the same data. When apt or apt-commands are run, it creates lock files in a few places. When the previous apt command was not terminated properly, the lock files were not deleted and hence they prevent any new instances of apt/apt-get commands.
Solution
To fix the problem, all you need to do is to remove the lock files of dpkg. Execute the following commands in the following order:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
After removing the locks, run the following command to reconfigure dpkg:
sudo dpkg --configure -a
Now if you try to run the command that was causing the trouble, you should be able to execute it without any problem.
Happy coding !