How to fix broken package error in Ubuntu

I am a great fan of Ubuntu am I am using it since Hardy Heron (Ubuntu 8.04 LTS). Presently, I am using Ubuntu 14.04 LTS majorly because of ROS Indigo support.

Recently, some of ROS packages got removed due to a silly mistake. In order to install these packages again, I removed complete ROS using following command-

sudo apt-get remove ros-*

Note that the above command is a bit risky and it should be the following

sudo apt-get purge '^ros-*'

The above command match only things that start with ros-, otherwise it will uninstall other packages that contain the string ros, like things with microsoft [1].

I installed ROS using sudo apt-get install ros-indigo-desktop-full so I think an easier way of uninstalling ROS should be the following-

ravi@lab:~$ sudo apt-get remove ros-indigo-desktop-full
ravi@lab:~$ sudo apt-get purge ros-indigo-desktop-full
ravi@lab:~$ sudo apt-get autoremove

Anyway, I tried to install ROS again and encountered broken packages error.

ravi@lab:~$ sudo apt-get install ros-indigo-desktop-full
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-indigo-desktop-full : Depends: ros-indigo-perception but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

After, I tried possible solutions but failed.

ravi@lab:~$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
ravi@lab:~$ sudo dpkg --configure -a
ravi@lab:~$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
ravi@lab:~$ sudo apt update                                                
ravi@lab:~$ sudo apt upgrade
ravi@lab:~$ sudo apt-get install ros-indigo-desktop-full
Reading package lists... Done
Building dependency tree      
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
 
The following packages have unmet dependencies:
 ros-indigo-desktop-full : Depends: ros-indigo-perception but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

In this blog post, I am going to explain how to fix broken package error. Note that the easiest way to solve this problem is re-installation of Ubuntu but that’s not the way, I want to.

Let’s look into the problem once more. The ros-indigo-desktop-full package depends on ros-indigo-perception. Hence, in order to install ros-indigo-desktop-full package, apt-get is going to install ros-indigo-perception. However, due to broken packages, this package can’t be installed.

So, let’s try to install ros-indigo-perception manually-

ravi@lab:~$ sudo apt-get install ros-indigo-perception
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-indigo-perception : Depends: ros-indigo-perception-pcl but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Oops! It didn’t work. Let’s try more-

ravi@lab:~$ sudo apt-get install ros-indigo-perception-pcl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-indigo-perception-pcl : Depends: ros-indigo-pcl-conversions but it is not going to be installed
                             Depends: ros-indigo-pcl-ros but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

No luck but don’t give up so early. Try more-

ravi@lab:~$ sudo apt-get install ros-indigo-pcl-conversions
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-indigo-pcl-conversions : Depends: libpcl-1.7-all but it is not going to be installed
                              Depends: libpcl-1.7-all-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
ravi@lab:~$ sudo apt-get install libpcl-1.7-all
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libpcl-1.7-all : Depends: libpcl-1.7-all-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
ravi@lab:~$ sudo apt-get install libpcl-1.7-all-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libpcl-1.7-all-dev : Depends: libpcl-apps-1.7-dev but it is not going to be installed
                      Depends: libpcl-io-1.7-dev but it is not going to be installed
                      Depends: libpcl-outofcore-1.7-dev but it is not going to be installed
                      Depends: libpcl-people-1.7-dev but it is not going to be installed
                      Depends: libpcl-recognition-1.7-dev but it is not going to be installed
                      Depends: libpcl-visualization-1.7-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

We are able to find out the package dependencies. I dug more and realized that the problem is occurring due to libusb-1.0-0. So let’s remove it-

sudo apt-get remove libusb-1.0-0

Note that libusb is a USB programming library that gives easy access to USB devices. Hence, while removing libusb, we might have removed many other critical libraries. So let’s fix these issues before powering off the machine.

First, let’s install ROS again (that’s what I was trying to do)-

sudo apt install ros-indigo-desktop-full
sudo apt-get install -f
sudo apt-get update
sudo apt-get upgrade
sudo rosdep init
rosdep update
sudo apt-get install python-rosinstall
mkdir -p ~/ros_ws/src
source /opt/ros/indigo/setup.bash
cd ros_ws/
catkin_make
catkin_make install
sudo apt-get install git-core python-argparse python-wstool python-vcstools python-rosdep ros-indigo-control-msgs ros-indigo-joystick-drivers

At this point, I still suspect that we haven’t recovered entirely but I think, we should be okay to go. It is the time to reboot the OS.

After rebooting, the login doesn’t work, and it says Failed to start session. Don’t panic, while staying at the login screen press CTRL+ALT+F1. It will take to the terminal. Use the credentials to login. Finally, restore the desktop using the following command [2]-

sudo apt-get install ubuntu-desktop

Hurray! We fixed it. We have ROS Indigo on Ubuntu 14.04 LTS without broken package error.

References

  1. https://answers.ros.org/question/57213?answer=192266#post-id-192266
  2. https://askubuntu.com/a/450679/569883
Written on June 1, 2018