You can clear the dpkg lock error on Ubuntu with one quick terminal command. First, run sudo rm /var/lib/dpkg/lock to free the stuck file. If that fails, force a new package setup with sudo dpkg --configure -a. On top of that, remove the cache locks in the apt lists and archives folders. This method fixes the block and lets you install apps again. In the end, your system update runs smooth and fast.
When you try to install a program via Synaptic or Terminal on Linux systems, you may sometimes get (/var/lib/dpkg/).
How to Resolve /var/lib/dpkg/ in Ubuntu
This error prevents you from installing a program from the Linux repositories. It usually occurs in a concurrent program installation. For example, if you’re using Ubuntu and you get this error when you try to install a program with APT, all you have to do is delete this folder.
I encountered this error while installing GNS3 IOU using apt on Ubuntu. In addition, the application you are trying to install may be different.
If the error you receive when trying to install software on Linux is as follows, we will solve the error (/var/lib/dpkg/lock) in this article.
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
Follow these steps to resolve this issue.
Steps:
Step 1
First, open Terminal on the Ubuntu desktop, type the command below, and press Enter.
sudo rm /var/lib/dpkg/lock
After executing the above command, try to install the program again. If you get the same error again, go to step two.
Step 2
In this step, perform the following command in Terminal to force a reconfiguration of Ubuntu packages.
sudo dpkg --configure –a
Try installing the program in Terminal again. Most likely, it will resolve. If you reencounter the same error, go to step 3.
After fixing your issue, it is important to keep your packages current. Often updating programs also stops new bugs. Based on my experience, many crashes are actually caused by partial updates. For a safe system, I suggest learning the Ubuntu program update steps.
Step 3
This time, try to resolve this issue by executing the following commands in Terminal. Then, try to install the program again. As a result, it will now resolve.
FAQ About the ‘/var/lib/dpkg/lock’ Block on Ubuntu
What exactly is this ‘/var/lib/dpkg/lock’ error a sign of?
This error is actually the system’s self-protection mechanism. If Ubuntu’s package manager tries to do two jobs at the same time, things get messy. At that moment, dpkg creates a lock file in the background. The file’s purpose is to tell other jobs: ‘Someone is working here, wait!’
The problem is that sometimes the job finishes but the lock file is not deleted. Or an update is cut off halfway and the file is left without an owner. When you try to install a new program, the apt command sees the lock file and panics. It yells at you ‘Resource temporarily unavailable’.
So the error message does not mean something bad happened. On the contrary, it is a watchdog that protects the stability of the system. The watchdog just fell asleep. Our job will be to gently wake it up and lift it out of its bed.
Is it safe to run the ‘sudo rm /var/lib/dpkg/lock’ command from the terminal?
Short answer: Yes, it is safe. But on one condition. It is safe only if there is not really an install or update running in the background at that moment. If apt is running in the background, then you have the risk of breaking the system’s package database.
Imagine a scene like this. The Ubuntu software center is silently downloading an update. And you are deleting the lock without knowing. If two different dpkg instances try to write to the same database, the result is disaster.
So what will we do? First, check with a ‘ps aux | grep apt’ command. If there is no listed apt or dpkg job, go ahead and delete it. You are not deleting the folder anyway. You are only removing the lock file there. After the deletion, apt will cleanly recreate its own lock.
I deleted the lock file but I still get the same error. What do I do now?
This happens often; do not panic at all. Actually Ubuntu gave you a second clue too. You just did not notice it. Besides the dpkg lock, apt also keeps locks in two other places. One is the directory with package lists. The other is the archive cache of downloaded packages.
This is why in the second step we run the friendly ‘sudo rm /var/lib/apt/lists/lock’ and ‘sudo rm /var/cache/apt/archives/lock’ commands. In addition, you may need to rough up the package manager a bit.
Type ‘sudo dpkg –configure -a’ in the terminal. This command restarts all setup jobs that were left half done. Just like an orchestra conductor gathering scattered musicians. In almost ninety-five percent of cases, the system recovers after these three. If it does not, do not worry, the solution is in our pocket.
What should I do for the ‘Unable to lock the administration directory’ error when installing a program?
Let me give you a workflow. You can write this on a post-it note and stick it to the corner of your monitor. First move: Check if there is a hidden apt left on the system with ‘ps aux | grep -i apt’. If something is running, wait two minutes. Waiting is sometimes the best system administration.
If nothing is running, go to the second move. Take down the main castle with ‘sudo rm /var/lib/dpkg/lock’. Then immediately sweep the area with ‘sudo dpkg –configure -a’. This command cleans up all jobs that were left half done.
If the error stubbornly keeps going, the third and final move comes. Paste the ‘sudo rm /var/lib/apt/lists/lock’ and ‘sudo rm /var/cache/apt/archives/lock’ commands in order. Then refresh the package list with ‘sudo apt update’. Now the green light is on to install.
The error is fixed, but why does this locking thing happen to me so often?
I am very glad you asked this question. Because the trick here is exactly hidden in your usage habits. The first scenario is this. You typed the apt command in the terminal and pressed enter. But the job took a bit long. You got bored and cut the job with Ctrl+C. At that moment, dpkg does not leave and go; it stays without an owner.
The second scenario is trying to use the software center and the terminal at the same time. While Ubuntu’s graphical interface is silently checking for updates in the background, if you open the terminal and type ‘sudo apt install’, a crash happens. The system gets confused.
The third and most hidden reason is the automatic update service. Especially on servers, if you manually interfere while ‘unattended-upgrades’ is running in the background, a lock is unavoidable. My advice is this. Before any apt job, check who is holding the file with ‘sudo lsof /var/lib/dpkg/lock’. If you make it a habit, you will never have a headache.
The delete commands did not work, the system still refuses. What is the last resort?
We are facing a stubborn locking case. A bit more aggressive intervention may be needed. Do not be scared right away. Restarting the system solves the problem fifty percent of the time. But we can handle it without restarting too.
First, let us rename all cache directories that might be locked. Do ‘sudo mv /var/lib/dpkg/lock /var/lib/dpkg/lock.bak’. Do the same for lists and archives. Renaming is safer than deleting. Then clean the dpkg database with ‘sudo dpkg –clear-avail’.
Finally, give the ‘sudo apt-get install -f’ and ‘sudo apt-get autoremove’ commands to forcefully fix package states. If all of this is not enough, which is very rare.
Then you can think about switching to the virtual console (Ctrl+Alt+F3) and stopping the graphical session. After saying ‘sudo service lightdm stop’, run the commands. This method silences all update triggers running in the background. Almost all problematic setups give up at this point.
Conclusion
In this article, we have examined step by step how to troubleshoot “Unable to lock the administration directory” on Linux. Thanks for following us!
They'll Thank You for Discovering This Guide!
Ready to do your loved ones a huge favor with just one click? Knowledge grows as it is shared.
Hi, I'm Tolga, a computer expert with 20 years of experience. I help fix computer issues with things like hardware, systems, networks, virtualization, servers, and operating systems. Check out my website for helpful info, and feel free to ask me anything. Keep yourself in the loop about the newest technologies!
Be the first to share your comment