Terminal commands - Updating Debian/Ubuntu

Sudo apt update indicates the number of packages that can be upgraded

Why learn terminal commands? Aren't terminal commands from 40 years ago?

Terminal commands, instructions you type at a text terminal, have been around for more than 40 years1. There's a reason people still use terminal commands more than 40 years later. Terminal commands can be both powerful and fast. Some people argue that terminal commands are complicated, and some are, but most commands are simple once you have a basic understanding of the command.

Graphical software can also be complicated. Take Microsoft Word for example. Word can be used to type out a novel. Entering a story into Microsoft Word is fairly simple. But this isn't all Microsoft Word can do. Styles can be used to arrange how Word displays chapter headings, sub-headings, and categories of content. Charts, graphics, and spreadsheets can be imported and modified in Microsoft Word. Word looks simple but it can also be used to create some very complex documents.

The same is true of commands in Linux. And like Microsoft Word + Microsoft Excel terminal commands can work together to be even more powerful.

A practical example: updating the software on your computer using terminal commands

Consider the example of updating your computer. While many graphical Linux systems will automatically notify the user of updates, it takes extra resources for that update notifier to pop up a window and notify the user. When the end user clicks to install updates it takes extra resources to draw progress bars and actually update the system.

Now consider the following commands (this is actually a couple of commands):

sudo apt update && sudo apt -y upgrade

This looks a bit complicated at first, but it's actually quite simple. In this complex-looking command there are really two commands to learn: sudo and apt.

Think of sudo as "Super User DO" (sudo) something. Super User DO this, Super User DO that. Sudo is simply a command that tells the system that you want to do something as if you were the "Super User" or "Administrator" of the system. Computers have had administrators/super users and regular users for a long time, but this concept might not be familiar since most Windows installations default to the user of the system being the administrator. For now just realize that sudo tells the operating system to do something as the super user/administrator.

Apt is the Advanced Package Tool (APT). Apt is not present on all Linux systems. Systems like Red Hat Linux use another package tool called dnf, which is an updated version of another tool called yum. Apt, dnf, and yum all are what are known as package managers, programs for managing packages/software. All of these programs can be used to install, update, or remove software packages from a Linux system.

The great thing about a package manager is that with one or two commands you can update ALL the software on your system. In fact the example we used at the top will look to the Internet (in what's called a repository) for a list of the latest packages for Debian/Ubuntu, download that list, make a comparison of versions of programs that are installed versus available, and update any software that's newer. If a newer version of Firefox is available in the repositories apt will know and download that version, then upgrade the installed version to the version that was just downloaded.

Let's unpack the example a bit further. Earlier I mentioned that there are two commands here: sudo and apt. There are also two different actions happening:

sudo apt update

Super User DO apt update. Super User update the list of software available with the current list of the versions of software available for download. Debian, Ubuntu, and other apt-based Linux distributions/collections of software have several of what are known as repositories. Repositories are online storage locations for software2. Software repositories get updated frequently with new versions of software. If you're having trouble with the concept of a software repository think of it like an "App store" on a phone.

The command sudo apt update tells the computer to pull down the latest information about what's currently in the software repository. If there's a newer version of some program apt will discover this when update is run.

Let's look at the second part of the example:

sudo apt -y upgrade

I threw a tiny bit of a curve ball here. Normally most people would simply put: sudo apt upgrade. I included -y in my example, and you'll see why in a moment. By itself sudo apt upgrade will look to see which packages need updating. It will then display the packages that will be upgraded and ask if you want to continue (expecting a Y or N answer). The -y I included in my example answers Y(es) to this question so you don't actually have to type the y to complete the upgrade.

The terminal commands 'sudo apt upgrade' shows the packages to be upgraded and the y/n prompt


As you might expect, the apt upgrade command is what actually upgrades the software on the system. Apt update looks to see if there are updates, and apt upgrade actually upgrades the software.

But what about the &&? Earlier I mentioned there are two parts to this example. You could have also typed this on two different lines:

sudo apt update
sudo apt -y upgrade

The && lets you complete both commands using only 1 line. Do this && do this other thing. I have purposefully given a somewhat complex example to start. Apt can be used to do much more than update and upgrade a system, but this is a good place to stop.

If you're coming to Linux with no experience this might have been a bit of a deep dive. If you already have Linux experience then this might have been a very long explanation for a concept you already know. Either way I hope this has shown that by combining a couple of simple commands you can do something powerful, update all the software on your system. We will dig into other things apt can do in a future article. Thanks for reading!

1. Unix - Wikipedia - https://en.wikipedia.org/wiki/Unix
2. Software Repository - Wikipedia - https://en.wikipedia.org/wiki/Software_repository