How to Fix ‘E: Could not get lock /var/lib/dpkg/lock’ Error in Ubuntu Linux

Having trouble trying to fix ‘E: Could not get lock /var/lib/dpkg/lock’ error in Ubuntu Linux?

Considering the benefits of using Linux-based operating systems, it makes sense why their popularity has been increasing as of late. Courtesy of Linux, users are sure to get a much better experience in terms of security, privacy, and software updates. 

However, those thinking about migrating to Linux are often intimidated by its CLI way of doing things. Well, you need not worry as Linux isn’t as difficult to use as some people make it out to be. As a matter of fact, Ubuntu and other such distributions have a user-friendly GUI with which you can easily perform most tasks.

Plus, it’s also possible to easily install different applications with the help of the Linux terminal or Ubuntu Software Center. However, with any of these methods, you can sometimes run into an error that says:

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?

If you’re not seeing this exact error, you may be seeing one of its variations. However, what the ‘could not get lock’ error in Ubuntu Linux suggests is that the system couldn’t access the Debian package manager service. 

Those facing this issue are in luck as we’ll tell you three different methods for successfully installing your applications.

So, let’s get started!

Method 1: Try Again or Reboot.

Method 2: Kill the Stuck Apt Service.

Method 3: Remove Lock Files.

Fixing ‘Could not get lock /var/lib/dpkg/lock-frontend’ Error.

Method 1: Try Again or Reboot.

Using the apt command for installing different applications mostly works. However, you could still run into an error or two on a bad day. Accordingly, if you’re facing the ‘could not get lock’ error in Ubuntu Linux, then maybe this method might work out for you.

There are no complications with this procedure as you just have to wait for about 10 minutes and go for the installation again. However, if that doesn’t work either, you can try rebooting your system after enabling the automatic updates.

If that sounds confusing, try following these steps:

  1. Start by clicking the Show Applications button on the bottom-right side of the screen.
  2. From there, you are to type “Updates” in the search box.

  1. Next, you need to click on Software & Updates from the available options and head to the “Updates” tab.
  2. From there, you’ll be able to set the update schedule as you deem fit.

could not get lock error on ubuntu linux

  1. Lastly, you can restart your computer and see if the installation works now.

Although waiting or rebooting the system might work, there are plenty of cases where you’d have to try another method to fix this issue.

Method 2: Kill the Stuck Apt Service.

If the first method isn’t working for you, then perhaps you should try checking the Apt services running on your system. For this method, you’ll have to first look for any unusual dpkg or apt service and then kill it. 

For this, you’d have to make use of the Linux terminal. However, you need not worry as we will tell you all the commands you have to run to complete this procedure. Just follow the given steps carefully, and you shouldn’t come across any issues.

Here’s how you can kill the stuck Apt service:

  1. First of all, open the Linux terminal by simultaneously pressing the Ctrl + Alt + T keys
  2. Once the terminal opens, you have to check the running installation services by running the following command:
ps aux | grep -i apt
  1. With this, you should now be able to see whether apt or apt-get is being used by any other processes. If you find any, it is possible to kill those processes by running the following command:
sudo kill <four_digit_process_id>

  1. Afterward, we recommend checking the running processes once again with the same command mentioned in step 2.
  2. If you don’t find any process, then you’re all set to try installing your application once again. However, if that’s not the case, you should try running the following command to force kill that process:
sudo kill -9 <four_digit_process_id>

Once you’ve completed this procedure, there’s a high chance that your installation should work now. However, if this method seems a bit complicated, you should try deleting the lock files, as shown below. 

Method 3: Remove Lock Files.

If our first two methods didn’t solve the problem, then removing lock files is sure to do the trick. You should go for this method if you’ve come across an error such as:

/var/lib/dpkg/lock

/var/lib/dpkg/lock-frontend

/var/lib/apt/lists/lock

/var/cache/apt/archives/lock

What this error suggests is that the lock files are not letting dpkg or apt use the same files at the same time. Although removing these files could solve the problem, remember that doing so could result in causing more errors. 

But, if you’ve made up your mind about this method, then the following steps should do:

  1. The first step is to open the Linux terminal by hitting the Ctrl + Alt + T keys.
  2. Next, you can remove the lock files by running the following commands one by one:
/var/lib/dpkg/lock

/var/lib/dpkg/lock-frontend

/var/lib/apt/lists/lock

/var/cache/apt/archives/lock
  1. Now, we also recommend reconfiguring dpkg with the help of the following command:
sudo dpkg --configure -a
  1. Finally, you can try installing your application again and see if the issue has been fixed.

Fixing ‘Could not get lock /var/lib/dpkg/lock-frontend’ Error.

Now, there is another type of error that you may come across while using Ubuntu Linux. More specifically, installations could also get interrupted by the following error:

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)

E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

With that being said, the good news is that you can get rid of this error in a fashion that’s similar to our other methods. So, let’s cut to the chase and have a look at the necessary steps:

  1. Firstly, press the Ctrl + Alt + T keys to open the Linux terminal.
  2. Once it appears, you need to run the following command for locating and killing the processes using the lock files:
sudo lsof /var/lib/dpkg/lock-frontend
  1. Now, your system could be installing a security update if you find “unattended” under the command column. In this case, you can either wait for the update to install or force kill that process with the following command:
sudo kill -9 <four_digit_process_id>
  1. With this, you’re now free to remove the lock-frontend files with this command:
sudo rm /var/lib/dpkg/lock-frontend
  1. Afterward, we also recommend reconfiguring dpkg by running the following command:
sudo dpkg --configure -a
  1. Lastly, you can execute the following command to make sure that the error has been fixed:
sudo apt update

You’d be able to tell that the “E: Could not get lock /var/lib/dpkg/lock” error has been fixed upon the successful completion of the process. 

Although Ubuntu is quite user-friendly, it can run into issues every once in a while, just like every other operating system out there. As you could probably tell, fixing the ‘E: Could not get lock /var/lib/dpkg/lock’ error isn’t that difficult either. 

Moreover, if you’re a Linux beginner, you should check out this article where we teach you how to zip files/folders in Ubuntu. 

If this guide helped you, please share it. 🙂

Author

Leave a Reply

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