How to fix Unable to lock the administration directory (/var/lib/dpkg/) in ubuntu

While working or installation new packages in Ubuntu, We might be get error like “Unable to lock the administration directory (/var/lib/dpkg/)”, Do not worry about that, You just need to do some step in your Ubuntu machine, The step are mentioned below :-

Step 1:- You need to get and force kill the apt process by using the following the commands.

ps -ef | grep apt

Command output :-

root@client:~# ps -ef | grep apt
root      1102     1  0 15:21 ?        00:00:00 /bin/sh /usr/lib/apt/apt.systemd.daily update
root      1130  1102  0 15:21 ?        00:00:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held update

root      2172     1  0 15:23 ?        00:00:00 /usr/bin/python3 /usr/sbin/aptd

root      2724  2109  0 15:26 pts/2    00:00:00 grep –color=auto apt

After getting all apt process ID you need to force fully kill the apt-get related process ID’s by using the following commands.

root@techbeginner:~# kill -9 PID

Step 2:- After this you need to delete the lock files and cache by using the following commands.

rm /var/lib/apt/lists/lock
rm /var/cache/apt/archives/lock
rm /var/lib/dpkg/lock

Step 3:- You need to reconfiguration package.

dpkg –configure -a

Step 4:- You should upate the ubuntu repo using apt-get update and you will see this time you wil not facing any kind of error.

root@techbeginner:~# apt-get update 

You should get this type of command output like this:-

Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease  
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease    
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Fetched 109 kB in 1s (62.3 kB/s)                            
Reading package lists… Done
Building dependency tree      
Reading state information… Done
513 packages can be upgraded. Run ‘apt list –upgradable’ to see them.

As you can see the there is no error found, Now you can install your packages, Still you have any issue, Comment me I will reply as soon as possible.

Conclusion

We have successfully fix ed Unable to lock the administration directory (/var/lib/dpkg/) in ubuntuKindly report in case you are facing difficulties with following details.

  • OS name
  • OS version
  • Package name
  • Logs – Error / Warning / failed
How to fix Unable to lock the administration directory (/var/lib/dpkg/) in ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top