DEV Community

Cover image for Ubuntu OS upgrade script
Bojan Jagetic
Bojan Jagetic

Posted on

6 2

Ubuntu OS upgrade script

Introduction

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
Enter fullscreen mode Exit fullscreen mode

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
fi
Enter fullscreen mode Exit fullscreen mode
  **NOTE ** you will only have to reboot machine in case packages were updated/upgraded
  if not you can just go with no
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹ī¸

👋 Kindness is contagious

If this article connected with you, consider tapping ❤ī¸ or leaving a brief comment to share your thoughts!

Okay