Debian

What Does dpkg Configure Do?

To fix this error, you can run the following command: You probably have tried to download or update a package/application and then ended up getting an error like this – dpkg was interrupted run dpkg –configure. It is widespread among beginners, and sometimes old users also encounter this error.

Before we get into Linux jargon and troubleshooting, let’s look at what exactly dpkg is. So, in simple words – dpkg is a package manager for Debian-based Linux distribution. If you are still confused, don’t worry; we will explain it from scratch. In this article, we will explain what does dpkg configure do and the usage of this command.

What is dpkg Command?

Let’s start with the basics, assuming you are using Debian, as dpkg configure is used in Debian-based systems. That’s why you are here to learn about this command. As said above, it is a package manager used for Debian.

So, what is a package manager? If you use Linux-based operating systems, you will often hear the term “package manager” term.

You probably have found .deb files (or packages) in your operating system. These files are called packages in general language. A package carries all types of files that come with a particular type of application.

The package manager is used to manage these packages. For the Debian system, we can use the dpkg command as a package manager for Installing, removing, and upgrading packages in Debian and Debian-based systems.

How to Use dpkg Configure

We use the dpkg command to manage packages on a Linux system, so let’s discuss how we can use dpkg configure easily.

Installing Program Using Dpkg Command

Here is the command to install a program by using dpkg:

$ sudo dpkg -i [package_name]

For example, we are installing Google Chrome using dpkg command:

$ sudo dpkg -i google-chrome-stable_current_amd64.deb

This way, you can install multiple applications using this command.

Removing a Program

You can list down the installed packages on your system by using the following command:

$ dpkg --list

Let’s say we have to remove the chrome package:

$ dpkg --remove google-chrome-unstable

Configuring a Package

Dpkg –configure one of the popular commands used to configure unpacked programs or packages.

Configuration command is used to unpack and configure the package. You can unpack packages with the following command:

$ dpkg --unpack [package_name]

Now, you can configure the package you have recently unpacked above. To configure it, use the following command:

$ dpkg --configure [package_name]

Troubleshooting: Dpkg was Interrupted

This error often appears when we are installing a new program or upgrading an old one. This might happen because you might not configure some of your packages properly, or background processes might be using the same file.

Method 1

A program Installation goes through the following steps in Debian systems.

  1. 1It extracts the files from the package.
  2. In case the app is already installed on the system, it initiates a new installation.
  3. The file unpacking starts along with backup. In case program installation gets interrupted for any reason, the system can start a new installation again.
  4. Lastly, the configuration process gets executed

Sometimes, if the program doesn’t get properly executed, it throws the error mentioned above, and it will create issues while installing or updating programs. Now execute the following command for fixing this error:

$ sudo dpkg --configure package... -a or --pending

When we run -a or –pending parameter with dpkg command rather than providing package name, all unpacked, but unconfigured packages are configured.

Now, start the installation or update process again to check if it is working or not. If it persists, you can try the following solutions.

Method 2

Run the following command to remove the updates first:

$ cd /var/lib/dpkg/updates

$ sudo rm *

Now, try to install or update the app again. For that, we will use the following command:

$ sudo apt update

$ sudo apt upgrade

If the system still throws errors, then it is because the system or other programs are using the file to update applications or the system, resulting in the locking of dpkg files.

When two processes simultaneously use the same file, the system locks the file, preventing unknown errors. You can check if the system is locking the dpkg file. Enter this command to check further:

$ ps aux | grep -i ap

After running the above command, if you see the result like usr/lib/apt/apt.systemd.daily lock_is_held update, this means the file is being used in another process run in the background.

It would help if you either waited to finish the background process or manually check and remove the locked files using the following command.

To check all the locked dpkg files, we will use the lsof command. lsof command list all the services running in the system. Therefore, we have used the following command one by one to get processes holding the dpkg file.

$ sudo lsof /var/lib/dpkg/lock

$ sudo lsof /var/lib/apt/lists/lock

$ sudo lsof /var/cache/apt/archives/lock

You will see that the command you have just entered above throws the one or more processes with the ID that you can terminate using the force kill command.

$ sudo kill -9 <ID>

Also, you can remove the lock files with these commands:

$ sudo rm /var/lib/apt/lists/lock

$ sudo rm /var/cache/apt/archives/lock

Finally, run this command to initiate the update process.

$ sudo apt-get update

Method 3

As you know, the “dpkg was interrupted” error occurs when two processes run to the same program. We will terminate the service or process locking the dpkg file using the following command on the command line terminal with this method.

Run this command to get services using the dpkg file in the background.

$ ps aux | grep -i apt

The command mentioned above will show you services running along with a unique ID as following:

Process 1: 1234 0.0 0.0 12×× ××××pts/2 .....

Process 2: 1234 0.0 0.0 12×× ××××pts/3 .....

In the above example, 1234 is our ID, so you will see the different IDs in the output. We will use these IDs to kill the running processes. To kill or terminate the particular process, enter the following command:

$ sudo kill <ID>

Now, rerun the following command to check if the process is still running.

$ ps aux | grep -i apt

If the process still appears on the system, you have to force kill it using the following command:

$ sudo kill -9 <ID>.

Another command you can use to terminate all the services using the dpkg file is:

$ sudo killall apt apt-get

Conclusion

We have a long list of Dpkg commands used for various operations on a particular file or package. Still, we have focused only on the dpkg –configure command in this write-up. We have explained the purpose of dpkg –configure while covering the use of dpkg commands on Debian-based systems.

Frequently, users end up getting configuration problems when installing a new program or updating an application. We also have described the reasons that cause such errors. Therefore, we have provided all the possible solutions to overcome this problem.

We hope you have found this article helpful and informative. If you still have any queries on suggestions, please let us know in the comment section.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.