How to upgrade Ubuntu 16.04 to 18.04 LTS using CLI

I am using Ubuntu Linux 16.04 LTS on Lionde. How do I upgrade Ubuntu 16.04 to 18.04 LTS using terminal bash shell over ssh based session?

Introduction : Ubuntu recommend upgrading a Server Edition installation by using the do-release-upgrade command. Part of the update-manager-core package, it does not have any graphical dependencies and is installed by default. This page shows how to use the recommended upgrade method for Ubuntu Linux 16.04 LTS.

Steps to upgrade Ubuntu 16.04 to 18.04

To upgrade on a server system:

  1. Login to Ubuntu box
  2. Make sure you keep backup all important data
  3. Patch current system by running sudo apt update && sudo apt upgrade
  4. After reboot makes sure either UFW firewall is temporarily disabled or TCP port 1022 is open
  5. To upgrade Ubuntu 18.04 LTS from 16.04 LTS run sudo do-release-upgrade
  6. Follow on-screen instructions to upgrade to Ubuntu 18.04

Let us see all commands and examples in details to ugrade Ubuntu 16 to 18 LTS.

WARNING: Always backup all data before typing any one of the following commands.

How to upgrade from Ubuntu Linux 16.04 to 18.04

Type the apt command or apt-get command to upgrade existing system:
$ sudo apt update
$ sudo apt upgrade

Reboot the Linux box if kernel was updated
$ sudo reboot
If you have a ufw firewall running on ufw, open ssh port 1022 using the following ufw syntax:
$ sudo ufw allow 1022/tcp comment 'Temp open port ssh tcp port 1022 for upgrade'

How to upgrade to Ubuntu 18.04 LTS using do-release-upgrade

Upgrade the operating system to the latest release from the command-line by typing the following command:
$ sudo do-release-upgrade

How to upgrade from Ubuntu Linux 16.04 to 18.04 LTS using the cli

Now follow on-screen instructions. During upgrade procedure, you may be promoted to replace existing grub or ssh config file. Make sure you choose to keep existing version to avoid problems:

Click to enlarge

After some time you will see “System upgrade is complete” message. Press y to restart your system to load updates kernel and operating system for your cloud server:


Login using the ssh command:
$ ssh user@your-ubuntu-server
Verify Ubuntu Linux kernel version with uname:
$ uname -r
Make sure all needed ports are open and running with the ss command or netstat command:
$ sudo ss -tulpn
$ sudo netstat -tulpn

Use grep command/egrep command or tail command/cat command to verify log files for errors:
$ dmesg
$ tail -f /path/to/log/files
$ egrep -i 'err|cri' /var/log/nginx/error.log

Upgrading Ubuntu 16.04 server to 18.04 LTS successfully

Remove tcp port 1022 added Ubuntu VM via ufw

Run following ufw command:
$ sudo ufw delete allow 1022/tcp


And there you have it Ubuntu Linux v16.04 LTS upgraded to v18.04 LTS running on cloud server. See this page for more info.

This entry is 1 of 5 in the Upgrade On a Ubuntu Server Tutorial series. Keep reading the rest of the series:
  1. How to upgrade Ubuntu 16.04 to 18.04 LTS using terminal
  2. AWS Lightsail upgrade Ubuntu 16.04 LTS to 18.04 LTS
  3. How Do I Update Ubuntu Linux Softwares Using Command Line?
  4. HowTo: Upgrade To a Newer Version of Ubuntu 14.04 LTS
  5. Upgrade Ubuntu 18.04 to 20.04 LTS using command line

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Sigit Wijanarko Oct 3, 2020 @ 19:11

    Thank you very much, I followed those steps, and able to upgrade my cloud server using terminal from Ubuntu 16 to 18 lts.

    Although now it seems during upgrade procedure, no promoted to replace existing grub or ssh config file.

    I’ll say it again, thank you very much.

  • Don M Oct 13, 2020 @ 3:18

    Thank you so much for this guide.

    After having to reinstall my Ubuntu OS starting with 16.04 LTS and progressing thru 18.04 LTS, to 20.04.1 LTS. ( I don’t understand what was happening as the 18.04.5 disks I had, simply would not allow me to boot my computer into a live session.)

    I was able to follow this tutorial, and it worked perfectly in helping me restore my MSATA Drive to a useful operating system. I can say that I never had to use the graphical interface. For the record, I used the command line ” sudo do-release-upgrade” , and then simply followed the prompts which I answered all with selecting yes.

    Once updated to 18.04.5, the application updater handled the rest. Everything worked perfectly.

    Thank you to everyone who makes the Ubuntu Community a success.

  • R Lutz Oct 22, 2020 @ 11:58

    sudo apt update
    sudo apt upgrade
    sudo reboot
    sudo ufw allow 1022/tcp comment 'Temp open port ssh tcp port 1022 for upgrade'
    sudo do-release-upgrade
    ssh user@your-ubuntu-server
    uname -r
    sudo ss -tulpn
    sudo netstat -tulpn
    tail -f /path/to/log/files
    egrep -i 'err|cri' /var/log/nginx/error.log
    sudo ufw delete allow 1022/tcp

  • usbdrive007 Jan 23, 2021 @ 10:21

    Hey, I wanna tell you that I updated my Google cloud server Ubuntu 16 to 18 with your instructions. Worked perfectly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @