How to upgrade Ubuntu from the command line

Sometimes you cannot use the graphical utility to upgrade Ubuntu, in which case you must use the command line to upgrade it.

Ubuntu's update manager makes it easier to upgrade the installation to the main release. The utility's graphical interface guides users to upgrade step-by-step, making it easier to follow and implement.

However, sometimes you cannot use the graphical utility on the server because there is no access to the graphical interface. In this case you must use the command line to upgrade Ubuntu.

  1. Instructions for managing programs in Ubuntu via the command line
  2. How to enable automatic system update mode on Ubuntu
  3. Simple way to update Ubuntu ISO file

Do-release-upgrade command with -d switch

The Ubuntu upgrade utility from the old version to the new version is called do-release-upgrade. This is a script written in Python programming language.

Picture 1 of How to upgrade Ubuntu from the command line

Typically, this script will upgrade from a stable release (or LTS - Long-term Support) to the next release. For example, it can update Ubuntu 16.04 to Ubuntu 18.04. However, when a new LTS version appears, you cannot upgrade it until the first point release is released. For example, if you are using version 16.04.5, you cannot upgrade to version 18.04 but wait until version 18.04.1 is released. The first new LTS release still has bugs, but if you really need the new LTS, you can use the command line switch to force the utility to update. So when you just released version 18.04 you can update it with the following command:

 sudo do-release-upgrade -d 

How to upgrade Ubuntu with the do-release-upgrade command

Before upgrading, you should temporarily disable a third-party repository (PPA) or entries you have added /etc/apt/sources.list and /etc/apt/sources.list.d/ . If you don't add any software repositories other than the repositories provided by Ubuntu, you can skip this step.

Picture 2 of How to upgrade Ubuntu from the command line

Some packages from these software repositories may affect new packages from the next Ubuntu release. Therefore you should run sudo apt update to refresh package information. Then, use commands like sudo apt autoremove nginx to delete the programs you have installed from third-party providers.

If there is no do-release-upgrade command on your system, install it with the following command:

 sudo apt install update-manager-core 

Usually it is installed by default. You need to update the software package before upgrading to a new version of Ubuntu. To update all packages on the system, run the following command:

 sudo apt update && apt upgrade sudo 

Update to Ubuntu for short-term support (Optional)

Even numbers, such as 18.04, are used for long-term support releases (LTS). odd numbers such as 19.04 are used for short-term releases. If the version you are using is long-term and wants to upgrade to the next long-term version, skip this step. If you are using a long-term version such as 18.04 and want to upgrade to version 18.10 or 19.04 (any subsequent versions available), edit this file:

 sudo nano / etc / update-manager / release-upgrades 

Change Prompt = lts to Prompt = normal , press Ctrl + X , then type y and press Enter to save the file.

Picture 3 of How to upgrade Ubuntu from the command line

Upgrade local computer

Although you can open terminal emulator software on a graphical computer, there is a problem. When the graphics server is upgraded, it can restart, causing the terminal session to be lost. So you should log out of that graphics session, then press Alt + Ctrl + F2 or Alt + Ctrl + F3 and log in to the TTY control panel before starting to use the upgrade script below.

Upgrade Ubuntu

Run the following upgrade script:

 sudo do-release-upgrade 

Now carefully follow the instructions on the screen. This tutorial will be slightly different depending on your upgrade script. For example, when connecting to an SSH session, you need to take one more step like the image below.

Picture 4 of How to upgrade Ubuntu from the command line

The next step, you need to handle the configuration file changes in the new package version.

Picture 5 of How to upgrade Ubuntu from the command line

If you have changed the configuration file mentioned, you can press N to keep the changes. If the server provider changes those files, press N. In case you and the provider do not make any changes, type Y to get the updated configuration file.

The upgrade process is not complicated, but there may be some problems depending on the level of 'clean' on your system (no third-party software repositories). After the update utility is complete, you need to restart the computer. Usually this script will provide options to reboot, otherwise you can run:

 sudo systemctl reboot 

Or more simply with the command:

 sudo reboot 

If there are no upgrade errors with the new software, everything will work when the machine restarts. If an error occurs, refer to the article How to fix Ubuntu update errors

I wish you all success!

Update 26 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile