Ошибка dpkg ubuntu

Многие новички могут по тем или иным причинам столкнуться с ошибками пакетного менеджера dpkg. Они могут возникнуть в случае прерывания установки (к примеру, завис компьютер), или при любой другой нештатной ситуации.

Пакетный менеджер dpkg позволяет устанавливать, удалять и получать информацию по пакетам. Он представляет собой основу системы управления пакетами в Ubuntu и других основанных на Debian дистрибутивах.

Базовый синтаксис dpkg следующий:

dpkg [опции] действие

Примеры использования dpkg

Установка пакета:

dpkg -i package-name.deb

Само собой, команда должна выполняться через sudo или от имени root.

Просмотр всех установленных пакетов в системе:

dpkg -l

Узнать детали по конкретному пакету:

dpkg -c packagename.deb

Удалить установленный ранее пакет:

dpkg -r package-name

Как исправить ошибку dpkg?

При появлении ошибок, связанных с менеджером пакетов, следует в первую очередь выполнить команду:

dpkg --configure -a

Команда производит настройку всех распакованных, но ненастроенных пакетов.

Однако бывает, что возникает ошибка «Не удалось получить доступ к файлу блокировки» («Unable to acquire the dpkg frontend lock»). В общем случае такое происходит, когда происходит установка пакетов в разных приложениях одновременно. Однако чаще такое случается при аварийной остановке установки приложения. В таком случае стоит удалить lock-файлы при помощи команд:

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

В случае, если ошибки менеджера пакетов все равно возникают, можно попробовать воспользоваться следующими командами:

cd /var/lib/dpkg/updates
sudo rm *
sudo apt-get update

If you are a person who uses Linux or its distros as their primary OS, there is a high probability that you have come across the annoying error message “dpkg was interrupted, you must manually run ‘dpkg –configure -a’ to correct the problem”.

You get this error when you are using the $apt-get command to install some packages or update your existing software packages, and the process gets killed.

Imagine you are required to update your favorite application, and you proceed to update it using the Command Terminal and the $apt-get command. The process is going along fine, but it stops suddenly, and you are presented with this error. It is very frustrating as you don’t know what went wrong and how to correct it.

The error can be caused by multiple reasons. You might have lost your internet connection, the package being installed was corrupted, or another issue you can’t point out. The problem with not knowing why the error occurred is that you can’t solve the issue straight away. You try out different things in the hope that the error is resolved.

For the users who are continuously experiencing this problem without any resolution, we will be taking a look at which commands you can execute on the Command Terminal to get rid of this error. So hang on tight, and let’s start the troubleshooting.

Commands You Should Run

When you get the dpkg error, the system advises you to configure the dpkg using this command.

Now, the majority of times you run this command, the dpkg tool is reset, and you can successfully return to reinstalling the package or whatever you were doing. However, there are instances where configuring dpkg doesn’t work, and you get the same error again and again. In such a case, you should execute the following commands.

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

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

$ cd /var/lib/dpkg/updates

$ sudo rm *

$ sudo apt-get update

These commands are a permanent fix whenever you are getting the dpkg error. Running these commands work most of the time, so you should try out these commands when you feel like you have hit a brick wall.

The $apt-get Command

The $apt-get command is a tool with which you can access the “Advanced Packaging Tool,” which is a library of all the software packages present in Linux. Through $apt-get you can download and install important software from authentic sources. $apt-get can also help get rid of and remove unwanted software and its dependencies from your Linux system.

Now, you can use multiple operators with $apt-get to perform multiple tasks respectively. We will be describing a few of them.

$apt-get install

As the name suggests, $apt-get install is used for installing software packages. By mentioning the name of the software, all its relative packages and dependencies will be downloaded and installed in your system. The syntax is very simple.

$ apt-get install <package name>

To install multiple packages, you can use this command.

$ apt-get install <package name1> <package name2>……..

You can also use $apt-get install in different ways. For example, if you want to install a specific software package version, you can use the following command.

$ apt-get install=version number

$apt-get update

This command is used for updating existing software packages in the “Advanced Packaging Tool” library to their latest versions. $apt-get update first checks for the latest version from the source and then downloads the latest version of all the packages.

$apt-get upgrade

$apt-get upgrade performs a similar job to $apt-get update, with the difference being that the software packages being updated are the ones present on your system. The command checks for the latest packages from the library, and if there is an update available for the desired software package, it downloads it and installs it.

$ apt-get upgrade package name

You can use it to also update multiple packages at a time.

$ apt-get upgrade package name1 package name2….

$apt-get remove

Again, as the name suggests, $apt-get remove is used for removing software packages from your Linux system. It performs the opposite job to $apt-get install.

$ apt-get remove <package name>

And for multiple packages,

$ apt-get remove package name1 package name 2….

$apt-get autoremove

Sometimes, the installed packages on your system require some important dependencies. These dependencies are installed automatically in your system, and when you uninstall that package, these dependencies remain there. To remove them, we use the $apt-get autoremove command.

$apt-get purge

This command performs a similar task to $apt-get remove. It uninstalls packages. The difference is that when you use “remove”, the configuration files are not removed for future use. If you want to get rid of the configuration files as well, use the $apt-get purge command.

$ apt-get purge package name

Conclusion

In this article, we discussed the “dpkg was interrupted; you must manually run ‘dpkg –configure -a’ to correct the problem” error received by users working on Linux and its distros. Users who have experienced it know that it is extremely difficult to deal with, so we discussed the commands you can use to get rid of this problem. We also described the $apt-get command and its different functions as a bonus. We hope that this article was able to help you out and if it did, please let us know in the comments.

About the author

Hi there! I’m a Software Engineer who loves to write about tech. You can reach out to me on LinkedIn.

It’s not uncommon to run into an issue of broken packages in Ubuntu and other Debian-based distributions. Sometimes, when you upgrade the system or install a software package, you may encounter the ‘Sub-process /usr/bin/dpkg returned an error code’ error.

For example, a while back, I tried to upgrade Ubuntu 18.04 and I bumped into the dpkg error as shown below.

Errors were encountered while processing:
google-chrome-stable
E: Sub-process /usr/bin/dpkg returned an error code (1)

This indicates that the google-chrome-stable package is either broken or corrupt. There are a few workarounds to this problem, so don’t throw in the towel yet or discard your system.

Solution 1: Reconfiguring the dpkg Package

One of the triggers of this error is a corrupted dpkg database. This can be caused by the sudden interruption of the installation of a software package. Reconfiguring the database is one way to resolve this issue.

To do this, simply execute the command:

$ sudo dpkg --configure -a

This reconfigures the unpacked packages that were not installed during the installation process.

Solution 2: Force Install the Troublesome Package

Sometimes, errors can occur during the installation of software packages. When such happens, you can force install the package using the -f option as shown.

$ sudo apt install -f
OR
$ sudo apt install --fix-broken

The -f option & --fix-broken can be interchangeably used to fix broken dependencies resulting from an interrupted package or cached package download.

Solution 3: Purge the Bad or Corrupted Software Package

If the first two solutions did not fix the problem, you can remove or purge the problematic software package as shown.

$ sudo apt remove --purge package_name

For example, in my case, purging the Google chrome package fixed the issue.

$ sudo apt remove --purge google-chrome-stable

Then invoke the commands below to remove all the old, unused, and unnecessary packages which also frees up space on your hard drive.

$ sudo apt clean
$ sudo apt autoremove

Solution 4: Remove all the Files Associated with the Package

Lastly, you can manually remove all the associated with the troublesome package. First, you need to find these files which are located in the /var/lib/dpkg/info directory as shown.

$ sudo ls -l /var/lib/dpkg/info | grep -i package_name

After listing the files, you can move them to the /tmp directory as shown

$ sudo mv /var/lib/dpkg/info/package-name.* /tmp

Alternatively, you can use the rm command to manually remove the files.

$ sudo rm -r /var/lib/dpkg/info/package-name.*

Finally, update the package lists as shown:

$ sudo apt update

You can thereafter give it another shot in reinstalling the software package.

Conclusion

This type of dpkg error points to an issue with the package installer usually caused by the interruption of an installation process or a corrupt dpkg database.

Any of the above-mentioned solutions should fix this error. If you have come this far, then it’s our hope that the issue has been successfully resolved and that you were able to reinstall your software package.

One of the common issue in Ubuntu and other Debian based distribution is the broken packages. You try to update the system or install a new package and you encounter an error like ‘Sub-process /usr/bin/dpkg returned an error code’.

That’s what happened to me the other day. I was trying to install a radio application in Ubuntu when it threw me this error:

Unpacking python-gst-1.0 (1.6.2-1build1) ...
Selecting previously unselected package radiotray.
Preparing to unpack .../radiotray_0.7.3-5ubuntu1_all.deb ...
Unpacking radiotray (0.7.3-5ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.2) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20180209-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Setting up polar-bookshelf (1.0.0-beta56) ...
ln: failed to create symbolic link '/usr/local/bin/polar-bookshelf': No such file or directory
dpkg: error processing package polar-bookshelf (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up python-appindicator (12.10.1+16.04.20170215-0ubuntu1) ...
Setting up python-gst-1.0 (1.6.2-1build1) ...
Setting up radiotray (0.7.3-5ubuntu1) ...
Errors were encountered while processing:
polar-bookshelf
E: Sub-process /usr/bin/dpkg returned an error code (1)

The last three lines are of the utmost importance here.

Errors were encountered while processing:
polar-bookshelf
E: Sub-process /usr/bin/dpkg returned an error code (1)

It tells me that the package polar-bookshelf is causing and issue. This might be crucial to how you fix this error here.

Fix update errors in Ubuntu Linux

Let’s try to fix this broken error package. I’ll show several methods that you can try one by one. The initial ones are easy to use and simply no-brainers.

You should try to run sudo apt update and then try to install a new package or upgrade after trying each of the methods discussed here.

Method 1: Reconfigure Package Database

The first method you can try is to reconfigure the package database. Probably the database got corrupted while installing a package. Reconfiguring often fixes the problem.

sudo dpkg --configure -a

Method 2: Use force install

If a package installation was interrupted previously, you may try to do a force install.

sudo apt-get install -f

Method 3: Try removing the troublesome package

If it’s not an issue for you, you may try to remove the package manually. Please don’t do it for Linux Kernels (packages starting with linux-).

sudo apt remove package_name

Method 4: Remove post info files of the troublesome package

This should be your last resort. You can try removing the files associated to the package in question from /var/lib/dpkg/info.

You need to know a little about basic Linux commands to figure out what’s happening and how can you use the same with your problem.

In my case, I had an issue with polar-bookshelf. So I looked for the files associated with it:

ls -l /var/lib/dpkg/info | grep -i polar-bookshelf
-rw-r--r-- 1 root root 2324811 Aug 14 19:29 polar-bookshelf.list
-rw-r--r-- 1 root root 2822824 Aug 10 04:28 polar-bookshelf.md5sums
-rwxr-xr-x 1 root root     113 Aug 10 04:28 polar-bookshelf.postinst
-rwxr-xr-x 1 root root      84 Aug 10 04:28 polar-bookshelf.postrm

Now all I needed to do was to remove these files:

sudo mv /var/lib/dpkg/info/polar-bookshelf.* /tmp

Use the sudo apt update and then you should be able to install software as usual.

Which method worked for you (if it worked)?

Donate Itsfoss

I hope this quick article helps you in fixing the ‘E: Sub-process /usr/bin/dpkg returned an error code (1)’ error.

If it did work for you, which method was it? Did you manage to fix this error with some other method? If yes, please share that to help others with this issue.

About the author

Abhishek Prakash

Abhishek Prakash

Created It’s FOSS 11 years ago to share my Linux adventure. Have a Master’s degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie and classic detective mysteries 🕵️‍♂️

Понравилась статья? Поделить с друзьями:
  • Ошибка dpf man
  • Ошибка dstc volvo c30
  • Ошибка dtc 5750 форд фокус
  • Ошибка dp exe при запуске игры дэдпул
  • Ошибка dsl соединения