In this article, I am going to show you how to update Ubuntu 20.04 LTS from the command line. So, let’s get started.

Configuring Automatic Updates:

By default, automatic update or unattended upgrade is enabled in Ubuntu 20.04 LTS.

If you want to configure automatic update, open the configuration file /etc/apt/apt.conf.d/20auto-upgrades with the following command:

$ sudo nano /etc/apt/apt.conf.d/20auto-upgrades

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Here, the first line APT::Periodic::Update-Package-Lists “1”; is used to tell APT package manager to automatically keep the package cache up to date.

The second line, APT::Periodic::Unattended-Upgrade “1”; is used to tell APT package manager to automatically update the packages.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

To disable automatic update or unattended upgrade, set APT::Periodic::Update-Package-Lists and APT::Periodic::Unattended-Upgrade to 0 as shown in the screenshot below.

Once you’re done, press X followed by Y and to save the configuration file.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Updating Package Repository Cache:

Before you attempt to install, update or remove any packages, you must update the APT package repository cache. This will update the package database of your Ubuntu 20.04 LTS machine and check if any newer version of the installed packages is available.

To update the APT package repository cache, run the following command:

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The APT package repository cache should be updated. As you can see, 35 packages can be updated to new versions.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Updating Specific Packages:

You can check the list of packages for which updates are available with the following command:

$ sudo apt list –upgradable

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The list of upgradable packages should be displayed. On each line, the package name is printed in green text color.

On the right of each line, the older package version is printed. On the left of each line, the newer available version is printed as marked in the screenshot below.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Now, to upgrade a single package (let’s say apport), run the following command:

$ sudo apt install apport

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

As you can see, apport and its dependencies (python3-apport) will be upgraded. These 2 packages are about 212 KB in size. So, about 212 KB of packages will be downloaded from the internet. Once they are installed, about 1024 B (bytes) of additional disk space will be used.

To confirm the upgrade, press Y and then press .

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The package apport and its dependencies should be upgraded.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Updating All Packages:

Instead of upgrading the packages one by one, you can upgrade all the available packages at once with the following command:

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

APT will show you the summary of the upgrade. Here, 33 packages will be upgraded. 5 packages will be newly installed. The upgrade is about 93.0 MB in size. So, about 93.0 MB of packages will be downloaded from the internet. After the upgrade, about 359 MB of additional disk space will be required.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

APT will show you the new packages which will be installed. Mostly new kernel and kernel header packages are displayed in this section.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

APT will show you the list of packages that will be upgraded.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

APT will also show you the old packages that are no longer required. You can safely remove them after the upgrade is complete.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Once you’re ready, press Y and then press to confirm the upgrade.

APT should start downloading all the required packages from the internet.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

After all the new packages are installed, the upgrade should be complete.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Now, reboot your computer for the changes to take effect with the following command:

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Locking Packages:

You can lock specific packages if you don’t want to upgrade them when you are upgrading all the packages using the sudo apt upgrade command.

First, list all the upgradable packages with the following command:

$ sudo apt list –upgradable

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

All the upgradable packages should be listed.

Now, let’s say, you don’t want the Linux kernel packages (linux-generic, linux-headers-generic and linux-image-generic) to be upgraded. You will have to mark these packages as hold.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

To hold upgrades for the package linux-generic, run the following command:

$ sudo apt-mark hold linux-generic

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The package linux-generic should be set on hold.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The same way, you can hold upgrades for the packages linux-headers-generic and linux-image-generic as follows:

$ sudo apt-mark hold linux-headers-generic linux-image-generic

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The packages linux-headers-generic and linux-image-generic should be set on hold.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

You can list all the packages which are set on hold with the following command:

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

As you can see, all the packages which I have set on hold are listed.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Now, try to upgrade all the packages as follows.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

As you can see, the packages (linux-generic, linux-headers-generic and linux-image-generic) which I have marked as hold are not going to be upgraded with the rest of the packages.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Unlocking Packages:

If later you decide to upgrade the packages which you have marked as hold, all you have to do is unhold them.

You can unhold the linux-generic package as follows:

$ sudo apt-mark unhold linux-generic

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The package linux-generic should not be on hold anymore.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

As you can see, the package linux-generic is not on the hold list anymore.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The same way, you can unhold the packages linux-headers-generic and linux-image-generic as follows:

$ sudo apt-mark unhold linux-generic linux-headers-generic linux-image-generic

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Now, if you upgrade all the packages, the packages linux-generic, linux-headers-generic, and linux-image-generic should also be upgraded.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Removing Unnecessary Packages:

Once the upgrade is complete, you can remove all the unnecessary packages with the following command:

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

In my case, no unnecessary packages are available.

If you have any unnecessary packages, they will be displayed and you will be asked to removed them. Just press Y and then press to remove them.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Cleaning Up Caches:

Once you have upgraded your computer, the newer version of packages will be cached in the /var/cache/apt/archives/ directory of your computer. You can remove them and free up disk spaces.

To remove them, run the following command:

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

The cached packages should be removed.

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

So, that’s how you upgrade Ubuntu 20.04 LTS from the command line. Thanks for reading this article.

About the author

How to Update Ubuntu 20.04 from the Command Line Interface ubuntu

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.