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.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Ubuntu 16.04 LTS
Est. reading time 15 minutes or more

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:
    sudo ufw allow 1022/tcp
  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 LTS.

Let us see all commands and examples in details to upgrade Ubuntu 16 to 18 LTS using the CLI over ssh-bases session.

WARNING: Always backup all data before typing any one of the following commands. The nixCraft and author is not responsible for any data loss.

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:

Verification

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

Conclusion

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig 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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep 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
10 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
    dmesg
    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.

  • Salifu Mar 19, 2021 @ 12:12

    Hi,
    thanks for this well written guide, I’ve used it to upgrade from ubuntu 16.04 to 18.04 LTS with ease.

  • Maryam Émeline Mar 30, 2021 @ 9:18

    Thank you for this guide. We updated three EC2 cloud servers. We are a small team working out in eastern Europe. We now have Python and PHP as per our needs.

  • MRK Apr 11, 2021 @ 20:34

    Currently I have ubuntu 16.04 in AWS EC2 with mongodb 3.2. Plan to upgrade ubuntu to 18.04. What is the compatible version of mongodb and is there a significant difference in mongo db? Does existing software work seamlessly in compatible mongodb version?

    • 🐧 Vivek Gite Apr 12, 2021 @ 5:59

      Ubuntu 18.04 comes with MongoDB version 3.6.3. Typically stuff works out of the box. However, this will update the whole OS and other apps like PHP, Perl, Python that you might use to access MongoDB. Hence, I recommend that you test everything offline in Ubuntu 18.04 LTS VM. Then only do updates. I hope this helps.

  • Gloria Enriquez Apr 12, 2021 @ 6:06

    Hola,

    Gracias por esta publicación.

  • john williams Apr 28, 2021 @ 7:33

    Hi,
    When I try to upgrade using these suggestions I get the dreaded: Error while moving the old database out of the way.
    I have tried various suggestions to get rid of this but with no luck.
    Regards,
    John

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum