Upgrading Ubuntu 18.04 to 20.04 for ROS users

Rahul Bhadani
Nov 7, 2020 · 7 min read
Image for post
Image for post
Image Courtesy: Alex Kulikov (https://unsplash.com/photos/BrunIOLQMfQ)

Who doesn’t love a new version of Ubuntu! And that too Long Term Support (LTS)! Lots of new features and designs but most importantly if you are a ROS user then you are definitely looking for a new version of Ubuntu since each new version of ROS with long-term support is tightly tied to an Ubuntu LTS. However, upgrading Ubuntu from an existing version to a newer is always a nightmare, especially when you have a plethora of third-party softwares installed. This was definitely the case with me.

In this article, I provide a step-by-step journey of upgrading Ubuntu 18.04 to 20.04 that I recently went through. Definitely, this journey is marred with trenches and pitfalls and as usual, one should be very careful while upgrading Ubuntu. If you don’t have an urgent need to install Ubuntu 18.04 to 20.04, it is always good to install Ubuntu from scratch. Nonetheless, I hope if you decide to upgrade Ubuntu 18.04 to 20.04, my article may prove useful. So let’s get started.

Disclaimer: Method I described here might not work for you. Hence, please, back up all your files, codes, etc. that you hold dearly to your heart and mind. This article is as per MIT license available at https://opensource.org/licenses/MIT

Step 0

sudo apt update
sudo apt upgrade
sudo apt-get update
sudo apt-get upgrade

Step 1

sudo update-manager -c

This will start software updater as follows and check for upgrade:

Image for post
Image for post

If your system has an upgrade available then it will ask if you are interested in upgrading. Press ‘Upgrade’ since I assume you came here to upgrade your Ubuntu. You will have to go to a series of questions, asking whether you want to continue. If you ROS installed in your system, it will also ask you if you want to proceed since each ROS version is tied to an Ubuntu OS version. Just press Yes, since this step is irrelevant and we will see later, why! Now the update manager will check for compatibility and download new packages. If everything is fine, you will be able to upgrade right away. However, seldom is the case that upgrade has gone smoothly.

First, the update manager will complain about the presence of third-party softwares and ask you to use ppa-purge to remove third party ppa. Even after you remove ppa for the third parties, the upgrade will not proceed because of the broken package manager. It will say

An unresolvable problem occurred while calculating the upgrade:
E:Unable to correct problems, you have held broken packages.
This can be caused by:
* Upgrading to a pre-release version of Ubuntu
* Running the current pre-release version of Ubuntu
* Unofficial software packages not provided by Ubuntu
If none of this applies, then please report this bug against the ‘update-manager’ package and include the files in /var/log/dist-upgrade/ in the bug report.

For me, the solution was to remove all broken packages. If you decide to take this route proceed with cautions.

I list cautions beforehand:

  1. Attempting to remove broken packages will uninstall almost all the necessary packages even some basic packages such as update-manager itself. Hence, I recommend before you do any of this, keep the terminal open, keep a browser open.
  2. Have an ethernet connection, rather than wifi. I think cable USB ethernet connection with Cell phone data will work as well
  3. Once the upgrade is complete, you will end with a desktop-less Ubuntu 20.04 and you will have to install a desktop by yourself. But there is a catch.
  4. Networking interfaces will be messed up and you will need to fix this before you can install any packages.
  5. Remember the hostname and username of the system.

Phew! Lots of problems. Once you pass through all these dangers, a new beautiful OS will welcome you. So read further.

Step 2

Image for post
Image for post

Select each ppa and click remove. Do not remove a ppa corresponding to Canonical, Canonical Partners, and Ubuntu 18.04 official.

Next, go to /etc/apt/sources.list.d and remove everything

cd  /etc/apt/sources.list.d
sudo rm *

Next, uninstall everything related to ROS

sudo apt-get remove ros-*

followed by

sudo apt autoremove

Step 3

An unresolvable problem occurred while calculating the upgrade:
E:Unable to correct problems, you have held broken packages.
This can be caused by:
* Upgrading to a pre-release version of Ubuntu
* Running the current pre-release version of Ubuntu
* Unofficial software packages not provided by Ubuntu
If none of this applies, then please report this bug against the ‘update-manager’ package and include the files in /var/log/dist-upgrade/ in the bug report.

When you go to /var/log/dist-upgrade/apt.log you will see that the log contains a list of packages that are broken. In my case, what I did was I uninstalled all broken packages. However, if you decide to do it, be sure, to keep the terminal open, and a browser open, in case, you need to search for something on the internet for troubleshooting. The reason is that while trying to uninstall broken packages a lot of other important packages will be uninstalled, and the browser is one of them, and I suspect that the terminal is one of them too. Uninstall the broken packages will not close the terminal but I am afraid you might not be able to find it again.

Okay, now since you have already analyzed the /var/log/dist-upgrade/apt.log you will realize that there may be hundreds of broken packages (this was the case for me). Hence, I wrote a bash script to automate the uninstallation of the broken packages.

Create a new file broken.sh in your home directory and enter the following code:

#!/bin/bash
brokenlines=$(grep Broken /var/log/dist-upgrade/apt.log)
echo $brokenlines
a=( $brokenlines )
next="yes"
for i in "${a[@]}"
do
if [ "$next" = "no" ];then
sudo apt-get remove $i -y
fi
if [ "$i" = "Broken" ]; then
next="no"
else
next="yes"
fi
done

Change its mode to executable by typing:

chmod +x ./broken.sh

and then execute the command.

./broken.sh

This is going to take a while, but be sure to keep your computer plugged in. Again, don’t close your terminal or your browser.

Step 4

sudo apt-get install --reinstall update-manager
sudo apt-get install --reinstall update-manager-core

After reinstalling update-manager, start the manager again by typing

sudo update-manager -c

and click on prompts upon asking and the update will start

Image for post
Image for post
Upgrade Manager
Image for post
Image for post
Remove the obsolete packages

and finally, restart the system

Image for post
Image for post

Once restart happens, you may find the system logs in into a pure black terminal and there is no desktop GUI. But the good news is that you now have Ubuntu 20.04. If that is the case with you, then sit tight. The ride is bumpy but you will get through it.

First, check if there is network service running by typing ping www.google.com

If it pings, then great, you can install Ubuntu-desktop right away by typing

sudo apt-get update 
sudo apt-get install ubuntu-desktop.

If not, then add the following to your /etc/network/interfaces

auto eth0
iface eth0 inet dhcp

Now, restart the networking service

service networking restart

In your case if it doesn’t work, then try:

systemctl start networking

or

systemctl enable NetworkManager

Then type

sudo dhclient

You might see an error

RTNETLINK answers: File exists
cmp: EOF on /tmp/tmp.qlfvdHMZt4 which is empty

But it didn’t affect me. I checked this post: https://askubuntu.com/questions/1254692/eof-error-when-running-dhclient-command

and I found out that /etc/hosts was okay for me. I retyped dhclient and this time I got

RTNETLINK answers: File exists

and thus I checked again by pinging

ping www.google.com

and it went through and I tried again installing a desktop

sudo apt-get update 
sudo apt-get install ubuntu-desktop

While installing, the install manager asked me a couple of question whether I want to keep existing settings or one from the package, I chose the package by typing Y and then the system restarted to the desktop GUI login

Image for post
Image for post
Ubuntu 20.04 login screen

Phew! Congratulation on finishing this bumpy ride with me. Now you can install ROS Noetic into your system without worrying about any dependency issues.

I hope this article was helpful.

References

  1. https://askubuntu.com/questions/202730/how-to-fix-the-unable-to-calculate-upgrade-issue-when-upgrading-from-12-04-to
  2. https://www.omgubuntu.co.uk/2020/04/how-to-upgrade-to-ubuntu-20-04
  3. https://askubuntu.com/questions/1268525/problems-to-upgrade-from-18-04-5-to-20-04-lts-again
  4. https://ubuntu.com/blog/how-to-upgrade-from-ubuntu-18-04-lts-to-20-04-lts-today
  5. https://itsfoss.com/how-to-remove-or-delete-ppas-quick-tip/
  6. https://www.reddit.com/r/ROS/comments/j8yjbl/updating_ros_when_upgrading_ubuntu/
  7. https://www.omgubuntu.co.uk/2019/12/how-to-remove-ppa-ubuntu

The Startup

Medium's largest active publication, followed by +754K people. Follow to join our community.

Rahul Bhadani

Written by

Pursuing Ph.D, Electrical Engg | Lecturer in Engineering | Intelligent Transportation & Quantum Science Researcher | https://www.buymeacoffee.com/rahulbhadani

The Startup

Medium's largest active publication, followed by +754K people. Follow to join our community.

Rahul Bhadani

Written by

Pursuing Ph.D, Electrical Engg | Lecturer in Engineering | Intelligent Transportation & Quantum Science Researcher | https://www.buymeacoffee.com/rahulbhadani

The Startup

Medium's largest active publication, followed by +754K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store