apt update vs apt 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 update
sudo apt upgrade
sudo apt 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 update” and “apt 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 update and apt 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.

Let’s have a second look at the following words

“apt update” updates the package sources list to get the latest list of available packages in the repositories

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

What is apt?

APT stands for Advanced Packaging Tool which is a tool that is used to manage software in our system and apt 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 and
  • 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

Also its worth mentioning that apt is just the improved version of apt-get, which essentially makes the user experience a little bit better by keeping things simpler. Most distros that support apt will also support apt-get as the functionality is almost the same. apt-get still has some features that apt doesn’t which makes it a good choice for scripting purposes.

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. 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.

This image has an empty alt attribute; its file name is image-230-1024x739.png

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

You can use the following command to make changes to this list

sudo apt edit-sources

I recommend not editing it unless you are sure what you are doing!

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!

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 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 upgrade” command

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

So when we enter the “apt 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 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 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 update
sudo apt 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 update &amp;&amp; sudo apt 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 full-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!

EI

We’re passionate about inventing embedded devices and we hope you are too! This blog deals with a wide variety of topics from C programming to IOT to networking certifications and more. Hope you enjoy your time spent here and hope you get some value out of our blog!

You may also like...