If you ever work with Debian Linux or one of the many Linux distributions that were derived from it, such as Ubuntu, you've probably seen or used the APT package manager. APT is how packages are installed, updated, and removed on such systems.

When using the command line, the apt update and apt upgrade commands can be used to update package repos and upgrade packages, respectively. In this guide, we'll be looking at the difference between the two commands and how they can both be used to upgrade installed packages on a Debian based system.

DID YOU KNOW?
You may also see apt-get update and apt-get upgrade commands used. We've written a full article explaining the difference between apt and apt-get, but suffice it to say that these commands perform basically the same functions as the corresponding apt commands.
In this tutorial you will learn:
  • What distros use apt update and apt upgrade?
  • What is the difference between apt update and apt upgrade?
apt update and apt upgrade commands being used to upgrade packages
apt update and apt upgrade commands being used to upgrade packages
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Debian Linux and most derivatives
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

What distros use apt update and apt upgrade?

Debian and Ubuntu are probably the most notable Linux distros that use APT (Advanced Package Tool) software which contains the apt update and apt upgrade commands, among others, that you are used to seeing. There are a lot of other distros that are based on Debian, and most of those also use APT.

Note that some Debian derivatives may put their own spin on the APT package manager, so it's not always guaranteed that apt commands will function the same on all distros. You would have to check the man pages with man apt on other distros to be sure. In this article, we're talking about apt in the context of its implementation on Debian and Ubuntu.

Other distributions with different package managers like DNF, YUM, Pacman, etc. will not be able to use the apt commands at all. Those package managers have their own functions and syntax, which may be very different from apt.


SUBSCRIBE NEWSLETTER & RSS
Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


What is the difference between apt update and apt upgrade?

apt update downloads package information from all configured sources (i.e. the sources configured inside /etc/apt/sources.list). This is how your system knows which packages are available for upgrade, and where to retrieve that software.

apt upgrade can then act on this information and upgrade all installed packages to their latest versions. This command will only upgrade packages that are already installed; it won't install new packages unless they are required for resolving dependencies. apt upgrade also won't remove any packages. If a package must be removed to complete an upgrade, the command will simply skip that upgrade and leave your current packages intact.

So why are these two commands separate?

Since the commands go hand in hand, many users wonder why they are even separate in the first place. It's extremely common to run the commands in quick succession, or even execute them on the same line, like so:

$ sudo apt update && sudo apt upgrade

The reason for separating the commands is because apt upgrade will attempt to upgrade every installed package on the system, which isn't always desirable. For example, what if you only want to upgrade to the latest version of Apache?

$ sudo apt update
$ sudo apt install apache2

Using the commands above, you can upgrade only the apache2 package and avoid upgrading the rest of the system. You could also use these commands to install Apache on a system which doesn't currently have it. In such a case, running apt update before the apt install command is still recommended so you end up with the latest version.

Now that you know the difference, it's also helpful to remember the commands apt full-upgrade and apt autoremove.

apt full-upgrade works very similarly to apt upgrade, except it also has the ability to remove packages from the system, if it's necessary in order to complete an upgrade. It's usually safe to use this command, but when in doubt, you can try an apt upgrade command first to see which, if any, packages get held back. All of these apt commands ask for confirmation before making any changes to your system.



apt autoremove can be used to remove lingering packages from your system that were only installed as dependencies for other packages. It's common to have a few of these packages hanging around after a sizeable upgrade. They're no longer needed, so there's usually not much sense keeping them. APT still needs you to issue this command, as it doesn't want to remove anything without your consent. Removing these old packages will free up some disk space and keep your system running clean.

It's most common to run it right after upgrading.

$ sudo apt update && sudo apt upgrade && sudo apt autoremove

Or, to breeze through the confirmation dialogs and further streamline the process, you can use the -y option.

$ sudo apt update && sudo apt -y upgrade && sudo apt -y autoremove

Closing Thoughts

In this guide, we learned about the difference between the apt update and apt upgrade commands on Debian based systems. Both commands go hand in hand, and are required for keeping software up to date. We also learned about apt full-upgrade and apt autoremove, two more APT commands that help keep our system up to date and clean.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.