Clean up package management after upgrading Ubuntu to a newer version
Solution 1:
Before upgrading to a newer release disable third-party repositories (PPAs) with the following command:
sudo sed -i 's/^/#/' /etc/apt/sources.list.d/*.list
sudo apt update
sudo apt upgrade
Sometimes the upgraded system will contain many unnecessary files, config files which aren't working with the new system, etc. Config files which aren't working are identified by the Ubuntu installer when upgrading. When I upgraded from Ubuntu 18.04 to Ubuntu 20.04 it took about an hour and I received one notification about a config file that needed to be edited. I copy/pasted the suggested edit into a text file and edited the config file after the upgrade was completed. It should be noted that if I hadn't watched the terminal output for the entire hour that it took to upgrade to 20.04 I would have missed the suggested edit which worked perfectly.
After the upgrading process is completed run the following commands:
sudo apt update sudo apt autoremove sudo apt clean deborphan # Install this package management tool with sudo apt install deborphan sudo reboot
Re-enable third-party repositories with the following command, which will remove the #
character from the lines that begin with deb.
sudo sed -i '/deb/s/^#//g' /etc/apt/sources.list.d/*.list
Change all instances of the old release codenames of the third-party repositories to the new release codenames. For example for an upgrade from
Ubuntu 18.04 to Ubuntu 20.04 the old release codename is bionic
and the codename of the upgraded release is focal
. To change all instances of bionic to focal in third-party repositories run the following commands:
sudo sed -i 's/bionic/focal/g' /etc/apt/sources.list.d/*.list sudo apt update
If you get an error message like:
E: The repository 'http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu focal Release' does not have a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default.
you will need to remove these repositories from your software sources with command(s) of the form:
sudo add-apt-repository --remove ppa:ubuntu-wine/ppa sudo apt update
For removing unnecessary files from the upgraded system I use the following commands:
sudo apt autoremove
sudo apt clean
-
deborphan
- Install this package management tool withsudo apt install deborphan
.
Running these commands after upgrading takes me about 5 minutes. My workstation has a lot of installed software. If I had done a fresh install instead of an upgrade configuring all the installed applications on my workstation would have taken me 2-3 days.
A successful upgrade is almost entirely dependent of your level of understanding of the Ubuntu operating system. Problems caused by an upgrade can almost always be solved if you have the level of skill necessary to solve them. When I am upgrading Ubuntu I keep a second laptop running alongside the computer being upgraded, so that I can immediately search Ask Ubuntu for the solution as soon as something goes wrong.