How to Fix Unable to Lock Database
When I try to update my machine by running
sudo pacman -Syyu I get an error saying it’s unable to lock the database. Below is an example:
But as you may have noticed, by removing a special database lock file, I was able to solve the issue. You can do this with
sudo privileges by running:
sudo rm /var/lib/pacman/db.lck
The above method is dangerous
I’ve done this before, and it’s worked perfectly fine with no issues. But the reason the
db.lck file exists is to ensure that only one program can run updates at a time. This prevents partial updates, or interrupted updates, or conflicts, or any other problems that can occur when two programs try to do the same update at the same time.
So before you go deleting your
db.lck file like I did, do yourself a favor and make absolute certain that there are no other programs trying to update anything. You can use the
lsof command to check what other programs are using the
lsof is short for “list open files”.
lsof command will either return nothing or a single number. If it returns nothing, that means that no process is currently using that file. If it does return a number, then that is the ID of the process currently using that file. In order to delete the file safely, you’ll need to kill that process first. You can do that by running
sudo kill -9 <process_id>
Hope that helps! Please leave a comment below if you have any questions. You can find more information on using the command line, check out this awesome book called The Linux Command Line. It’s free!