Debian Ubuntu Utilities

What is Apt-get upgrade and dist-upgrade commands and how to use them

As a regular user or system administrator, you probably have used the package management tools apt or apt-get at some point in Linux. We can use these package management tools in order to manage certain operations such as searching for available packages, installing new packages, removing the existing ones, updating, and upgrading the installed packages, etc.

If we talk about updating the packages, Linux operating systems come with a lot of free software updates for each package. It continuously releases the updates, patches, and fixes in order to improve the performance and fix bugs in them. It is very important to regularly check for these updates and install them in order to safeguard the system against potential threats and vulnerabilities. For installation of these updates, upgrade is performed and there are two ways to achieve this: one is apt-get upgrade and the second one is apt-get dist-upgrade. There is some difference between these two ways that often confuse users. This article will help you to understand and differentiate the apt-get upgrade and apt-get dist-upgrade.

Upgrading Package Database

To keep your system up to date, update and upgrade commands are used. The update command only updates the package list with the latest available versions, however, it does not install or upgrade the package. The upgrade command actually upgrades and installs the latest versions of packages that are already installed.  Before going to upgrade the packages, check for the updates as follows. It will let the apt-get to know the new versions available.

$ sudo apt-get update

What is Apt-get upgrade

To install the latest versions of all the previously installed packages on your system, apt-get upgrade is used. This command only upgrades the packages which have a new release available as stated in the sources.list file in the “/etc/apt” folder. It does not attempt to install a new package or remove any installed package on its own.

To upgrade or install the latest versions, run the following command as sudo as an only privilege user can check for and install updates on the Linux system:

$ sudo apt-get upgrade

To upgrade a specific package, command is as follows:

$ sudo apt-get upgrade <package_name>

What is Apt-get dist-upgrade

Similar to apt-get upgrade command, the apt-get dist-upgrade also upgrades the packages. In addition to this, it also handles changing dependencies with the latest versions of the package. It intelligently resolves the conflict among package dependencies and tries to upgrade the most significant packages at the expense of less significant ones, if required. Unlike apt-get upgrade command, the apt-get dist-upgrade is proactive and it installs new packages or removes existing ones on its own in order to complete the upgrade.

In order to upgrade the packages, run the dist-upgrade command with sudo privileges:

$ sudo apt-get dist-upgrade

To upgrade a specific package, command is as follows:

$ sudo apt-get dist-upgrade <package_name>

Sometimes, when you run apt-get upgrade, you receive the message “The following packages have been kept back”. These packages are kept back because in order to install their new version, they need some other package which is not already installed. And as we have discussed, the apt-get upgrade only upgrades the existing packages, neither installs a new package or removes an existing one. That is why it keeps these packages back. Sometimes, the packages are also kept back because of broken dependencies (when the package which it depends on does not have a downloadable version).

While with apt-get dist-upgrade, the new dependent package will be installed to resolve the dependency.

To conclude, if you want to only upgrade the packages without installing or removing them, go for the apt-get upgrade. On the other hand, if you want to upgrade no matter whether any new package is installed or the existing package is removed to fulfill dependencies, go for apt-get dist-upgrade.

About the author

Karim Buzdar

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn.