How to upgrade Ubuntu 16.04 to 18.04 LTS using terminal

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

kbd { display: inline-block;
margin: 0 .1em;
padding: .1em .6em;
font-family: Arial,”Helvetica Neue”,Helvetica,sans-serif;
font-size: 11px;
line-height: 1.4;
color: #242729;
text-shadow: 0 1px 0 #FFF;
background-color: #e1e3e5;
border: 1px solid #adb3b9;
border-radius: 3px;
box-shadow: 0 1px 0 rgba(12,13,14,0.2), 0 0 0 2px #FFF inset;
white-space: nowrap;}

To upgrade on a server system:

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

Let us see all commands in details.

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 ugprade

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 [email protected]
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 16.04 LTS upgraded to Ubuntu 18.04 Linux LTS running on cloud server. See this page for more info.

This entry is 1 of 4 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

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.