Ubuntu OS upgrade script

Photo by Jr Korpa on Unsplash

Ubuntu OS upgrade script


Upgrading Ubuntu OS has not been easier than this. I had need to upgrade multiple Ubuntu machines from 16.04 to 20.04 version. As you probably know every second number is LTS (Latest stable version) so in order to jump to second LTS you need to install first 18.04 and afterwards you can install 20.04. So I made this little bash script in order to make my life easier.

What this bash script do

Basically this script just runs commands needed to upgrade the OS, you will still need to confirm/disaprove prompts that you will get while upgrading.

Script breakdown

Updating and upgrading packages

First block of commands are just for updating apt packages and upgrading dist. It looks something like this:

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

sudo apt-get dist-upgrade

After this block you should need to rebboot your machine, so I made simple prompt which asking you for reboot

echo -n "Do you want to reboot machine? (y/n) \n"
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
    # Reboot machine
    sudo reboot
  **NOTE ** you will only have to reboot machine in case packages were updated/upgraded
  if not you can just go with no

Running OS upgrade

After machine is rebooted, you can run this script once again, this time you will not need to reboot the machine again, so when prompted go with no

Next block of commands will run the actual upgrade of the Operating System and it looks like this

sudo do-release-upgrade -c
sudo do-release-upgrade

While installing you will get multiple prompts which you need to answer. After everything is finished you will get prompt that says that reboot is required so go with yes

Results output

So finally this bash script will just print your current release version

cat /etc/os-release  | grep VERSION
lsb_release -a