apt update && apt upgrade: Command Explained for Beginners!

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.

In this article, I have tried to explain what this command means from a beginner’s perspective avoiding unnecessary “technical terms” and I have tried to keep this article concise so that you can get through the entire article in about 10 to 20 mins max!

For those of you in a hurry here is the short version of the answer!

The Short Version of the Answer

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.

What does the “&&” do? The double-ampersand is an operator telling the bash terminal to first execute the command before the && operator and if that command was successfully executed without any errors, then go ahead and execute the command after the “&&” operator.

Also worth noting is that this double-ampersand is not specific to the apt command used here, we can use that with any bash commands!

I can see that the above paragraph has too many “technical terms” (which I promised not to use!) but that is just the short version of the answer to explain the command “sudo apt update“, so do not worry if you don’t understand every word in that paragraph!

By the end of this article we will get back to this short answer version and by that time I am sure you will be able to understand what every word meant in the short answer above!

So let us begin!

apt update && apt upgrade: A Thorough Explanation!

The Fundamentals

Before getting into the command itself, lets get our basics strong by answering the following question

How Do Commands Work?

In this video we have explored the nature of the command line interface and the ideas behind its creation.

Let us next explore the answer to the question “What does apt do?”

What does apt do?

APT stands for Advanced Packaging Tool which is a tool that is used to manage software in our system and apt is the software used to communicate this APT software management tool.

The words “manage software” in the above paragraph 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 interested to learn more about how software packages are managed in Linux I highly recommend reading the article in the link below.

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

Hence the apt command is responsible for installation, removal, and updating of software in our system.

A good analogy is to think of your computer as a factory and the apt command as the manager in that factory who is responsible for the installation of new equipment, removal of equipment that is no longer needed, and update desired equipment to their latest versions, while maintaining records of the equipment names and versions which are currently present in the factory.

factory

Let us first learn what these commands individually mean and then combine them once we understand them each separately!

apt update

The screenshot below shows what the output of the command apt update looks like.

output: sudo apt update

Your output might look a bit different than mine, but the important things to note here are the “Hits”. All of these web addresses are repos that contain software. As you can see the last line says “Reading package lists… Done” which means that my computer went ahead and read all the available software in the repos and compared them with the version present on my end and found that they are up-to-date!

Continuing with our factory analogy, assume our manager is maintaining an excel sheet containing the list of parts available from various equipment manufacturers. Here using the sub-command update we are telling our manager to contact all the equipment manufacturers and get data regarding the latest available equipment and redo his excel sheet!

So in essence, what we are doing when we enter this “sudo 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 our computers!

That is the meaning of the sudo apt update command!

Next have a look at the sudo apt upgrade command

apt upgrade

The output of the command “sudo apt upgrade” is shown in the screenshot below

output1: sudo apt upgrade

Your output might look a bit different than mine, but the important things to note here is the line that says “The following packages will be upgraded:”. The packages mentioned in the following line have newer versions available no the repo and once you press “Y”(for yes) and press the “Enter” button, the apt application will download and install the updated packages on your Linux machine as shown in the screenshot below.

output2: sudo apt upgrade

For example say software_X has version 1.2.2 installed on our system, but a newer version, say 1.3.1 is available in the repo. After running the sudo apt upgrade command, software_X will be updated to version 1.3.1.

Continuing with our factory analogy, let us say all the workers are using a 2015 Macbook model for doing all computer tasks. Now by giving the “upgrade” command to our manager, we are in essence telling him to buy the latest available Macbook and replace the old ones!

That is the meaning of sudo apt upgrade

Now the time has come for us to put those commands together using the && (double ampersand) operator and see how that goes!

sudo apt update && sudo apt upgrade

The screenshot below shows the output of the command line “apt update && apt upgrade

output: apt update && apt upgrade

As you can see, instead of stopping at “Reading Package lists… Done” the command continues to execute and prints out the output for the apt upgrade command.

I hope now you can understand the command!

The next logical question that comes to mind is…

Why not have a single command to replace “apt update && apt upgrade” 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!

But of-course, 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 && sudo apt upgrade

This will go ahead and do them both, as the update command rarely fails anyways!

But how will the terminal know if the first command has failed?

When we execute any command from the bash shell, the command will tell the shell if the output is a success or a failure using something known as a “exit status” which is a simple integer value. In Linux “exit status” of 0 (zero) means success and any other integer is tied to a particular error.

So the bash shell makes the call whether to execute the second command or not based on this exit status. Also usually some error message is printed on the terminal if the first command is a failure.

For example consider the screenshot below, where I have purposely entered an invalid command before our double ampersand (&&) operator.

As you can see the apt update command here did not run as the first command has failed to execute with an error printed on the console!

If you still have an incomplete feeling about what this command does, I suggest reading the 2 articles below

“sudo apt update” Command Explained For Beginners!
“sudo apt upgrade” Command Explained For Beginners!

Where I have answered the following questions in more detail

  • Command Line Interface vs Graphical User Interface: What is the need to have these 2 interfaces?
  • What is a command-line?
  • What do the 3 words in our command (sudo, apt, and update) mean?
  • Why do we need this command before we install software? and
  • Where to get more information about these commands?

If you wish to learn more and become a Linux pro, I suggest heading over for the recommended study materials to get started!

Recommended Study Materials Linux

And with that, I will conclude this article!

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

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

Here are some of our other articles that might be interesting to you!

A Step By Step Plan To Learn Linux The Fun Way..!
apt & apt-get Explained For Beginners!
DNF vs APT: Similarities and Differences Analyzed!
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