apt-get update vs apt-get upgrade: Differences Explained!

When I was a complete beginner and I needed to install something on my Ubuntu machine, I went online and typed in “How to install <software name> on Ubuntu” and it led me to a page with some commands which looked like this

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install <software name>

I was just happy that I was able to type something in the Terminal and it actually worked! I did not pay much attention to what I actually typed in. I guess to beginners, it just feels like a magic spell to get something installed!

As time went on, so many of my google searches led to using very similar patterns of “apt-get update” and “apt-get upgrade” commands to install stuff.

In plain English, update and upgrade have almost the same meanings, so it can get confusing for a beginner to understand what these commands actually do. Let’s see the difference between these 2 commands and what happens internally once you execute these commands.

What is the difference between apt-get update and apt-get upgrade? “apt-get update” updates the package sources list to get the latest list of available packages in the repositories and “apt-get upgrade” updates all the packages presently installed in our Linux system to their latest versions.

This is the short version of the answer. Let me expand what is written above with some more details.

The Fundamentals

Before we could understand the differences between the 2 commands, we must first be able to answer the following question

How does commands work?

Here is a video we made to the answer to the question above!

Now that we have covered the fundamentals lets get back to the topic!

First, let’s try and understand what apt-get is and then let’s see what these lists contain and why they need to be updated time to time.

What is apt-get?

APT stands for Advanced Packaging Tool which is a tool that is used to manage software in our system and apt-get is just a command used to communicate this APT software management tool. The words “manage software” simply refer to these 5 basic tasks

  • install software
  • remove software
  • upgrade software
  • upgrade system
  • maintain the list of software that is installed in our system

If you are a complete beginner I highly recommend reading the article in the link below before continuing with this one.

A Beginners Introduction To Linux Package managers: apt, yum, dpkg & rpm

What are packages in a Linux System?

Let’s start with this most basic question. Linux OS is basically made up of 3 parts

  • The hardware
  • The Linux Kernel and
  • Software packages that work with the Kernel to give us a complete Operating System

Hardware, as we know, is CPU, HDD, SSD, RAM all the components that make up your system.

Kernel acts as an interface between software and hardware.

Software packages can be application software like text editors, word processors, etc. or they can be the GNU utilities like bash, cron, dd, etc., or they can be device drivers to talk to the hardware.

Next, let’s have a brief look at what is included in these “Packages”

Contents of packages

The content of the packages managed by these package managers involves the following 4 main components

  • Binaries or the executable programs
  • metadata files containing the version, dependencies, signatures and other relevant information
  • documentation and manuals
  • configuration files

These packages are stored in places called repositories.

What are Repositories?

This is the next question we must address. Repositories (or repos for short) are basically a place where verified packages are stored for easy retrieval and installation. They can be online like the APT repository or they can be on a local folder or a DVD where you have a special collection of software that you need.

You can have several repositories from which you can download and install these packages. These can be

  • official repos of your particular distro (some have guaranteed support while others are not entirely supported) and
  • 3rd party repos

What is a Package Source List?

This is a list of packages available for installing on a given distro. This list is maintained by your Linux machine. The information in this list usually includes the locations of various repositories from which software can be installed. These locations are usually on the internet.

This list is usually stored in the /etc/apt directory. This list is usually stored in the /etc/apt directory. You can view and edit this list the same way you can view any other text files using one of your favorite text editors like gedit or nano or vim.

You can also view this list by typing in the following command in the Linux terminal

cat /etc/apt/sources.list

The screenshot below shows the output of the above command.

As you can see from the above screenshot, this list basically contains some URLs to locations on the internet. From these locations, further information can be collected like

  • the latest bug fix updates
  • the latest version of each available package in the main repo
  • the latest version of each available package in the partner repos

If a particular URL has “#” in front of it, it will be ignored as comments. Let’s go ahead and visit one of these repos to see what it actually contains. You can try going to this link. The screenshot below shows its contents.

Downloading and extracting the Sources.gz file gives a file named “Source” with no file extension. You can open it using any text editor and it reveals a massive, more than 28,000 lines long file!

The screenshot above shows one of the packages named zsh (an alternative of bash shells), and the information it contains. As you can see it contains information like

  • the latest version of the software
  • the dependencies of this particular software etc.

So basically what we are doing when we enter this “apt-get update” command is we are asking our Linux machine to go browse these lists and copy the latest version of them and put them in your local machine!

Now let’s have a look at the “apt-get upgrade” command

“apt-get upgrade” updates all the packages presently installed in our Linux system to their latest versions.

So when we enter “apt-get upgrade” command we tell our Linux machine to compare the versions of all the presently installed packages with the ones in the list we have just downloaded through “apt-get update” and upgrade the packages which are lagging in terms of version numbers!

For example, consider this situation. Let’s assume that all the packages in the system are up-to-date with their version numbers equal to the ones presented in the list, except one, let’s call it “Package-X”, which has a version number of 2.4 while the list says version 3.0 is available. In this scenario, once we enter the “apt-get upgrade” command, your machine only upgrades this “Package-X” to the version 3.0. I hope you got the point!

Why are these 2 commands separate if they need to be used together all the time?

The answer is there are situations where we don’t need to use them together! Maybe you need to install a specific newly released software and leave the rest of the system untouched. In that case, all you need to do is enter the following commands

sudo apt-get update
sudo apt-get install <package name>

See how we skipped the upgrade command!

If you really need to upgrade all the packages in your system in a single line of command, you can also enter something like

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

This will go ahead and do them both!

How to upgrade the Linux Kernel?

The Kernel is a special part of the OS and messing it up can mean messing up the entire system! Hence we have a special command for upgrading it

sudo apt-get dist-upgrade

The above command will basically upgrade everything in your system, all the packages, and the kernel to the latest versions as supported by your repositories!

It does so in a smart way so that it automatically deletes the leftover unnecessary packages to free up your harddisk as a bonus!

How to upgrade to the latest version of Ubuntu?

For example, if you are presently using Ubuntu 18.04 and Ubuntu 19.04 is the latest version of Ubuntu and you wish to be upgraded to 19.04 then the command to use is

sudo do-release-upgrade

This will completely transform your packages and kernel to the latest release!

And with that, I will conclude this article!

I hope you guys enjoyed this article and learned something useful. 

You can email us or contact us through this link if you have any questions or suggestions.

If you liked the post, feel free to share this post with your friends and colleagues!

Photo of author
Editor
Balaji Gunasekaran
Balaji Gunasekaran is a Senior Software Engineer with a Master of Science degree in Mechatronics and a bachelor’s degree in Electrical and Electronics Engineering. He loves to write about tech and has written more than 300 articles. He has also published the book “Cracking the Embedded Software Engineering Interview”. You can follow him on LinkedIn

Comments are closed.