Score:4

Clean up package management after upgrading Ubuntu to a newer version

us flag

I am afraid of upgrading my Ubuntu because half of the time when I upgrade, I get a broken system that I must reinstall. So I always do it on weekends and very rarely.

I have a Dell XPS 13 9310 and the last two times I tried to upgrade I got a black screen while doing it, and had to reinstall Ubuntu, because it wouldn't boot anymore.

Are there tips so I can try to prevent this from happening again?

cocomac avatar
cn flag
Upgrading, especially on a supported path, shouldn't have big issues like that. I would suggest [reporting a bug](https://askubuntu.com/q/5121). Generally, take a backup of anything important. Also, even if it won't boot, you can probobly recover a lot, if not all, of your files by using a live CD. See [this question](https://askubuntu.com/questions/569679/) and [this question](https://unix.stackexchange.com/q/1067/) for backing up your data.
user535733 avatar
cn flag
Such failure is very unusual, so there likely are not many useful "tips" beyond preparation for failure (backups). Were it my system, I would review the logs around the time of such a failure -- software developers like to log the causes of as many failures as they can think of. Possible solutions depend upon the cause.
us flag
@cocoma losing stuff is not a problem, I'm actually used to it so I have backups of everything, but this always happens, even on a XPS 13 which is officially supported.
cocomac avatar
cn flag
But if you have backups, then why are you concerned about having to reinstall. It isn't ideal, but it shouldn't be that hard if you took backups. One additional thing... make the `/home` a separate partition if you reinstall, as that will help later
heynnema avatar
ru flag
If you have an Nvidia card, make sure your drivers are current BEFORE attempting the upgrade. Use the `Software & Updates`, Additional Drivers tab, app to do so.
waltinator avatar
it flag
If your method constantly fails, change (fix) your method. Also, make use of AskUbuntu's search feature. Maybe someone else has already solved a similar problem.
lemrm avatar
th flag
@GuerlandoOCs Have you [read this](https://askubuntu.com/search?tab=votes&q=sudo%20apt%20install%20upgrade), maybe helpful.
karel avatar
sa flag
@Nmath That's a logical misuse of the XY Problem link. The purpose of a fire hydrant is to provide water to fire trucks so they can put out fires, because it's too late to solve the problem if the house has already burned down. Reviewing a question like this as too broad is wrong, otherwise the reader can't be warned about a possible mistake *before* he makes that mistake.
Paul avatar
us flag
There may be some other better way to go about this, but the next time you are preparing to run an upgrade, post all of your hardware and everything and what you are planning to do. It possibly will get closed as duplicate, but that's fine if the duplicate has the answer you need. Also, if things go bad, then you can post why the solutions did not work. In an ideal world, this is great for everybody.
karel avatar
sa flag
@Nmath Your preceding comment was constructive. The question was ambiguously worded before I edited it, but I'm not sure that my edit fully resolves the original close vote reason. Please read it and see what you think.
Nmath avatar
ng flag
@karel I think it's sufficiently resolved and voted to reopen
Score:4
sa flag

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 with sudo 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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.