Linux Commands

Apt-Get Update vs Apt-Get Upgrade

The apt-get update and apt-get upgrade are two of the most common Linux commands. You can’t escape them, so making your peace by understanding their difference is your best solution. Besides, anytime you need a clean install of packages, you must use the two commands. If you don’t understand what the two commands imply and what their differences are, stick around and learn.

Working With APT in Linux

Packages get installed, updated, and removed using the APT package manager in Linux. Ubuntu and Debian are the common distros where you meet the advanced package tool (APT). The apt-get update and apt-get upgrade are the examples of the commands that fall under APT.

You can’t use the apt if you use the other distros like CentOS. Instead, you can use the package managers such as YUM.

Linux Apt-Get Update

Any package installed in Linux has its package information stored in the system. As the new version is released, the Linux system keeps a tab of the information that changes for each package. It achieves that using the apt-get update or apt update command. When run, the apt-get update downloads the package information that is defined in the sources file.

The package information is stored in the /etc/apt/sources.list which contains the URLs that directs where to source each package.

You can view the listed sources using an editor of your choice or using other commands like cat. The sources list is different based on your region.

Once you run the command, your system knows which packages should be updated based on the retrieved information. If all the packages are up to date, you can get the following:

In some cases, you get the following output which indicates that some packages need to update.

Linux Apt-Get Upgrade

When you run the apt-get update command and get that some packages need to upgrade, that’s when you run the apt-get upgrade. The apt upgrade or apt-get upgrade uses the information obtained to upgrade all the installed packages to the latest version. It only upgrades the installed packages and not the new packages.

For instance, we can upgrade the packages identified in the previous image as shown in the following:

Now that we covered the apt-get update and upgrade commands, let’s understand their differences.

Difference Between Apt-Get Update and Apt-Get Upgrade

The apt-get update is responsible for updating the package information using the URLs defined in the sources list. Once the information is updated, the apt-get upgrade takes over and upgrades all the installed packages with the latest version. Any package with no recent release gets skipped.

That’s the difference between the two commands. And in most cases, you might notice that they get used side by side. Always remember to update before upgrading. When installing a new package, update the apt database, install the package, and then upgrade the system.

Also, running the apt-update before installing a tool ensures that you get the latest version of the tool that you want to install. If you wish to upgrade only a single tool, let’s say git, you only need to run the two following commands without the apt-get upgrade.

$ sudo apt-get update
$ sudo apt install git

Note that the output indicates that git is already the newest version. That’s because we first executed the apt-get update command.

If you need to update and upgrade all packages, you can combine the two commands and run one command.

$ sudo apt-get update && sudo apt-get upgrade

You might notice that the system updates the package information first and proceeds to upgrade the packages if anything needs an upgrade. In the previous output, all packages are up to date.

Conclusion

You may easily get confused about why you need to execute the apt-get update and apt-get upgrade commands on your system, especially if you are a beginner. We’ve covered each command separately and discussed their differences. With that, you can now comfortably use your system’s apt-get update and apt-get upgrade commands.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.