Need Assistance?

In only two hours, with an average response time of 15 minutes, our expert will have your problem sorted out.

Server Trouble?

For a single, all-inclusive fee, we guarantee the continuous reliability, safety, and blazing speed of your servers.

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

Encountering the E: Could not get lock /var/lib/dpkg/lock error in Ubuntu is a common issue that typically arises when the package management system is already in use or has not been properly released by a previous process. Addressing this error promptly is essential to maintain system stability and ensure smooth package installations or updates. In this article, we will provide a detailed approach on How to Fix ‘E: Could not get lock /var/lib/dpkg/lock’ Error in a secure and efficient manner.

When trying to install a package in Ubuntu , you may encounter the error message:

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?

This can be frustrating, but it’s a common issue that occurs when another process is using the system’s package manager. The error occurs when Ubuntu locks the dpkg directory during software installations or updates. This lock prevents multiple processes from modifying the package database simultaneously, which could result in a broken system. Here’s how you can resolve it.

Check if an update is running

Open your terminal and run:

ps aux | grep -i apt

If you see that apt is being used by a program like apt.systemd.daily update, , wait for it to complete before trying again.

Find and kill running processes

While the previous scenario is straightforward and can be easily resolved, it may not always be that simple. If another program is using apt, a different approach will be required to handle the situation.

ps aux | grep -i apt

Use the process id to terminate the process by sending the SIGTERM signal.

sudo kill <process_id>

 Check if the process was killed by running the ‘ps aux | grep -i apt’ command.If it is still running , force kill it.

sudo kill -9 <process_id>

Remove the lock files (if necessary)

In some cases, the root cause may be the lock file. When the apt or apt-get commands are executed, they create lock files in several locations. If a previous apt command didn’t terminate correctly, these lock files are not removed, preventing any new instances of apt or apt-get from running.

To resolve the issue, you simply need to remove the lock files. However, before doing so, it’s a good idea to stop any processes that are currently using those lock files. 

For getting the list of process using the lock files, run:

sudo lsof /var/lib/dpkg
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock

The commands may not return anything or may return a single number. If they do return a number, use it to kill the process. Then safely back the lock files or remove them.

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

Conclusion

The “E: Could not get lock /var/lib/dpkg/lock” error usually occurs when another process is actively using apt or when a previous apt operation was not properly closed. While following standard troubleshooting steps can sometimes resolve the issue, persistent errors may indicate deeper system conflicts.If you’re encountering challenges with How to Fix ‘E: Could not get lock /var/lib/dpkg/lock’ Error, Skynats is here to help. Our expert team, through our comprehensive Linux Server Management services, offers professional, around-the-clock support to resolve such issues efficiently. Reach out to us today for fast and reliable assistance!

Liked!! Share the post.

Get Support right now!

Start server management with our 24x7 monitoring and active support team

Let us know your requirement.

Can't get what you are looking for?

Get Support Right Away!

Thank You

We have received your query and will get back to you soon.