Fix Ubuntu Without Reinstall

This brief tutorial describes how to easily fix broken Ubuntu OS without losing data and without reinstalling it completely.

Fix Broken Ubuntu OS

First of all, try to login with live cd and backup your data in an external drive. Just in case, if this method didn’t work, you can still have your data and reinstall everything!

At the login screen, press CTRL+ALT+F1 to switch to tty1. You can learn more about switching between TTYs here.

Now, type the following commands one by one to fix the broken Ubuntu Linux.

$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/lib/dpkg/lock
$ sudo rm /var/lib/dpkg/lock-frontend
$ sudo dpkg --configure -a
$ sudo apt-get clean
$ sudo apt-get update --fix-missing
$ sudo apt-get install -f
$ sudo dpkg --configure -a
$ sudo apt-get upgrade
$ sudo apt dist-upgrade

Finally, reboot the system using command:

$ sudo shutdown -r now

You can now be able to login to your Ubuntu system as usual.

After I followed these steps, all of my data in Ubuntu 18.04 test system was there and everything is the same as I left it. This method may not work for everyone. However, this small tip worked for me and saved a couple minutes from reinstalling. If you know any other better way, please let me know in the comment section. I will add them in this guide as well.