Home Arch Linux How To Fix “unable to lock database” Error In Arch Linux

How To Fix “unable to lock database” Error In Arch Linux

By sk
Published: Last Updated on 195.4K views

The other day, I was about to update my Arch Linux system. When I try to update the system, I encountered with "unable to lock database" error in Arch Linux. I could not install or remove any packages. This brief guide explains how to fix "unable to lock database" error in Arch Linux and its variants such as EndeavourOS and Manjaro Linux.

Root cause of "unable to lock database" Issue

The "unable to lock database" error in Arch Linux typically occurs when another process is already accessing the package database, such as a package manager or software update tool. This error prevents you from performing certain package management operations.

A lock file named /var/lib/pacman/db.lck is created by Pacman to ensure that only one instance is modifying the system package database at any given time, preventing potential corruption.

To resolve this issue, verify if any other package manager or software updater is currently running. Sometimes, you may have accidentally opened multiple instances of package managers or update tools. Close any currently running package management tools or it is better to wait for them to finish their operations.

If there are no active package management processes, you can delete the lock files manually as shown in the following steps.

Fix "unable to lock database" Error in Arch Linux

Here is the command that I entered to update my Arch Linux system:

# pacman -Syu

And, It returned the following error:

:: Synchronizing package databases...
error: failed to update core (unable to lock database)
error: failed to update extra (unable to lock database)
error: failed to update community (unable to lock database)
error: failed to update multilib (unable to lock database)
error: failed to synchronize any databases
error: failed to init transaction (unable to lock database)
error: could not lock database: File exists
 if you're sure a package manager is not already
 running, you can remove /var/lib/pacman/db.lck
Fix unable to lock database error in Arch linux
Fix unable to lock database error in Arch linux

The beauty of Linux distros is sometimes they occasionally present error messages along with explicit solutions.

As you can see in the above output, it says: ".. you can remove /var/lib/pacman/db.lck".

So, I simply deleted the aforementioned file with command:

$ sudo rm /var/lib/pacman/db.lck

Voila! It worked. I can then able to update, install and remove without any problems.

$ sudo pacman -Syu

Sample output:

:: Synchronizing package databases...
 core 122.8 KiB 162K/s 00:01 [######################] 100%
 extra 1771.8 KiB 249K/s 00:07 [######################] 100%
 community 3.3 MiB 256K/s 00:13 [######################] 100%
 multilib 163.5 KiB 265K/s 00:01 [######################] 100%
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Packages (8) ca-certificates-mozilla-3.22-1 coreutils-8.25-1 curl-7.47.1-1
 gcc-5.3.0-4 gcc-libs-5.3.0-4 libgcrypt-1.6.5-1 nano-2.5.2-1
 pacman-mirrorlist-20160208-2

Total Download Size: 42.79 MiB
Total Installed Size: 187.90 MiB
Net Upgrade Size: 0.91 MiB

:: Proceed with installation? [Y/n] y
:: Retrieving packages ...
 gcc-libs-5.3.0-4-x86_64 12.7 MiB 261K/s 00:50 [######################] 100%
 coreutils-8.25-1-x86_64 2.1 MiB 262K/s 00:08 [######################] 100%
 ca-certificates-moz... 363.0 KiB 241K/s 00:02 [######################] 100%
 curl-7.47.1-1-x86_64 798.3 KiB 263K/s 00:03 [######################] 100%
 gcc-5.3.0-4-x86_64 26.1 MiB 247K/s 01:48 [######################] 100%
 libgcrypt-1.6.5-1-x... 403.5 KiB 244K/s 00:02 [######################] 100%
 nano-2.5.2-1-x86_64 407.0 KiB 262K/s 00:02 [######################] 100%
 pacman-mirrorlist-2... 5.3 KiB 408K/s 00:00 [######################] 100%
(8/8) checking keys in keyring [######################] 100%
(8/8) checking package integrity [######################] 100%
(8/8) loading package files [######################] 100%
(8/8) checking for file conflicts [######################] 100%
(8/8) checking available disk space [######################] 100%
:: Processing package changes...
(1/8) upgrading gcc-libs [######################] 100%
(2/8) upgrading coreutils [######################] 100%
(3/8) upgrading ca-certificates-mozilla [######################] 100%
(4/8) upgrading curl [######################] 100%
(5/8) upgrading gcc [######################] 100%
(6/8) upgrading libgcrypt [######################] 100%
(7/8) upgrading nano [######################] 100%
(8/8) upgrading pacman-mirrorlist [######################] 100%
warning: /etc/pacman.d/mirrorlist installed as /etc/pacman.d/mirrorlist.pacnew

Hope this helps.

You May Also Like

32 comments

Harsh Sanmukhani April 22, 2020 - 3:01 pm

thanks it works for me…. 🙂

Reply
Mohammed May 23, 2020 - 7:17 am

Thank you so much it works

Reply
Yash July 12, 2020 - 6:31 pm

I got error : failed retrieving file core.db

Reply
sk July 13, 2020 - 11:24 am

It could be due to Arch Linux mirror problem. Choose a nearest working mirror and try again. Also check if you have enough space in /var directory. More details in this thread -> https://forum.manjaro.org/t/error-failed-retrieving-file-core-db-from-another-way-to-update/11534/11

Reply
IMM August 26, 2020 - 11:29 am

Hey. I use ‘Thunar Root’ to open ‘/var/lib/pacman/’ then I delete ‘db.lck’
It works for me
Hope this help

Reply
Kunle Apata August 8, 2021 - 10:05 am

Please how do you use Thunar root to delete the lock files.
Thank you.

Reply
sk August 8, 2021 - 6:27 pm

Hi Kunle,

Open Terminal and run the following command to open Thunar file manager as root:

pkexec thunar

Browse the file location and delete it normally. Please make sure you have selected the correct file name before deleting it.

Reply
Fruitser August 15, 2022 - 10:45 am

I just used the pacman GUI to update the mirrors and it fixed it for me. I think it had something to do with the fact that my internet failed right when i was last updating the mirrors.

Reply
Moein from iran September 27, 2020 - 2:26 am

thank you a lot

Reply
btw November 10, 2020 - 4:46 pm

Thx 😀 <3

Reply
Matthew November 6, 2021 - 7:45 am

No such file or directory error cannot remove help

Reply
sk November 6, 2021 - 11:32 am

Share the output of the following command:
sudo pacman -Syu

Reply
ramani July 1, 2023 - 8:17 am

# pacman -Syyu
:: Synchronizing package databases…
core.db failed to download
error: failed retrieving file ‘core.db’ from de3.mirror.archlinuxarm.org : Failed to connect to de3.mirror.archlinuxarm.org port 80 after 1425 ms: Couldn’t connect to server
error: failed to synchronize all databases (download library error)

Reply
sk July 1, 2023 - 2:22 pm

It is either mirror problem or Internet connectivity issue. Please make sure the Internet is working on your Arch Linux system. If it works, one of the software mirror is not working. You can retrieve latest Mirror list using Reflector as shown in this guide -> https://ostechnix.com/retrieve-latest-mirror-list-using-reflector-arch-linux/.

Reply
Sami February 19, 2022 - 4:16 am

Thanks, it worked.

Reply
riza July 28, 2023 - 5:48 pm

thankful bro , it’s work

Reply
johny why September 14, 2023 - 12:52 am

For me, the fix was just to restart arch. I had a previous abnormal shutdown.

Reply
1 2 3

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More