This article is all about demystifying the “sudo apt install” command by learning what it does and how it does it!
For those of you in a hurry, here is the “Short Version” of the answer!
sudo apt install: In a Nutshell!
A simple answer to the question: what does “sudo apt install“ do?
sudo apt install is the command used to download the latest available version of your desired application and install that application on your Linux computer.embeddedinventor.com
Sounds simple enough right? I am sure you already knew that part before clicking on this article!
- where does apt download our apps from?
- what if the application we want is not in the place where apt usually downloads from? and
- how does it know which is the “latest version”?
All these questions are addressed later in the article. You can jump to the section of interest using the table of contents below!
Also don’t worry if the above answer does not make sense to you as that was targeted at more experienced programmers who just wanted to refresh their memories. The rest of this article is dedicated to those of you in the first steps of your journey to becoming a Linux Expert!
sudo apt install: A Thorough Explanation
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 usually led me to a page with some commands which looked like this
sudo apt install <software name>
I was just happy that I was able to type something in the Terminal and see it actually working!
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 our favorite software installed!
As time went on, so many of my Google searches led to using very similar patterns of “apt install” commands to install stuff and my curiosity got the better of me, which inspired me to learn what these commands do and what happens in the background when you execute these commands.
I decided to put together everything I learned into an “easy-to-digest” article so that it can be useful for beginners!
Without further ado, let’s begin!
Let us start with the following question.
How Do Commands Work?
For those of you who love learning via videos, here is one we made to explain this concept!
If you are looking for some quiet reading time, then skip the video and read on!
Nowadays we are all used to applications with fancy graphical user interfaces, with buttons to click and forms to enter data.
But back in the era when graphics hardware was not capable enough to handle fancy graphical user interfaces, people interacted with the computers with simple text-based commands.
This interface is called the Command Line Interface (CLI)
The structure of these “text-based commands” usually looks like this
<software name> <option to click inside software>
If apt were a modern-day application, its interface will likely look something like this
So when you type in the terminal
sudo apt update
what you are doing is opening an application named apt and clicking the button named update!
So next time you look at any Linux command don’t let all the jargon overwhelm you as it’s just an app with some buttons!
Before looking at what happens when you click on the update and upgrade buttons, let us first learn how apps are managed in a Linux system with apt.
What is apt and how it works?
If you are a complete beginner I highly recommend reading the article in the link below before continuing with this one.
Let us start our discussion by answering the following question.
What is apt?
APT stands for Advanced Packaging Tool, which is a tool used to manage apps a.k.a “software packages” that are installed in our system.
The words “manage” above simply refer to these 5 basic tasks
- install software
- remove software
- upgrade software
- upgrade system and
- book-keeping/maintaining the list of software installed in our system
Also, it’s worth mentioning that apt is just the improved version of apt-get. apt essentially makes the user experience a little bit better by keeping things simpler. apt-get still has its uses though. If you wish to explore this topic further we have an excellent article on that topic linked below. (you can go ahead and skip the “Nutshell answer” section and start reading from the “Thorough Explanation” section!)
Coming back to the topic, to understand the role of apt on our systems consider the following analogy.
If your computer is an office and your apps are employees then you can think of apt as the manager who is responsible for the hiring and firing of the employees (apps)embeddedinventor.com
Now that we know what apt is, it is time to learn how apt works!
How apt works?
Similar to AppStore and PlayStore, Linux apps also come from marketplaces where developers can upload their apps and which are then verified to be free from malware and made ready to be downloaded.
In fact, the very idea of a “centralized location for storing verified software” originated in the world of Linux before it made it to iOS and Android!
These official “app stores” where you can find apps a.k.a “software packages” are called “repositories” in Linux.
apt enables you to keep track of what software is already installed on your system, what versions they are and what are the latest versions available in the market.
An oversimplified version of the apt’s database is presented in the picture below.
Every time we install or delete apps on our systems apt makes sure this database gets updated and maintained so that it portrays the present situation accurately.
Apart from the bookkeeping, apt also enables us to install, delete and update apps that are installed on our system by communicating with repositories in the cloud.
This is of course just the big picture and if you want to get into the nitty-gritty details we have a separate article on that which you can find in the link below!
Now that we understand what apt is and how it works, we are ready to answer the question: what does sudo apt install do?
What does sudo apt install do?
Let’s try and install the famous GNU text editor gedit using the apt install command.
Your output might look a bit different than mine, but the important things to note here are the first 2 lines.
The first line in the screenshot above says “Reading package lists… Done” which means that apt went ahead and read the local database maintained by apt.
The database entry for gedit may look like this
From this apt now knows where this app is, and what version is available there. With that information apt carries on to the next step.
The second line in the screenshot says “Building dependency tree” which means the apt is trying to see which other packages are required to make our desired package “gedit” to run.
A good analogy here would be installing a kitchen in your new apartment.
You cannot install a sink for the kitchen before installing the countertop and the cabinets. Here kitchen sink depends on the countertop, shelves, and cabinets.
Similarly, in the world of software, apps are built to depend on each other. In the case of gedit, it depends on the following list of packages
Now that apt knows what software to download and where to download them from, the next step is to get our permission to start the download process.
Hence apt tells us what additional packages will be downloaded and installed and how much extra space will be needed. Once we confirm this list by typing the letter “Y” and pressing enter, apt will download and install everything for us.
So that is how apt install works!
In the example above, everything went smoothly as expected. But what happens if apt could not find the application we want?
Let us see, shall we?
What if apt cannot find the Software Application?
Let’s try to install google chrome on our Ubuntu machine!
Apt could not find google chrome in any of the databases and gives up with an error message!
Solution#1: Manually download and install using apt
In this case, we can download the app directly from Google’s servers and ask apt to install it for us using the following commands
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo apt install ./google-chrome-stable_current_amd64.deb
Here the wget command downloads the app from the URL provided and apt install installed the app for us!
How did I know where to download Chrome from? No magic there, just googling! (source)
Although in this case we manually downloaded the app and installed it, in many cases the software we need is usually available in some online repo which is not added to the database apt maintains.
Let us see how we can do that next!
Solution#2: Add the repo to apt
For example, if you want Microsoft apps, you can find them in the following web address
This contains a bunch of Microsoft software like VS code, Azure, Dot-net, etc!
You can add this list to the database apt maintains using the add-apt-repository command, and next time you need any application from this repo, apt will automatically fetch them for you!
Below is the documentation of the add-apt-repository command.
In other words,
The add-apt-repository command is used to add more places for apt to search for software packages.embeddedinventor.com
If you wish to learn more about the “/etc/apt/source.list” file and about repositories and how they all fit in, we have an excellent article on that topic which you can find in the link below!
Make sure you completely trust the repos you wish to add them to the source.list file, when in doubt stick to the official repos!
Another interesting fact is that there is another command which does exactly the same thing.
sudo apt-get install
Notice here we use the command apt-get instead of the command apt. Both apt and apt-get have their place in the Linux operating system, you can learn more about their differences in the article given below.
Alright, I will stop here, hope you have enjoyed reading this article and found it useful!
If your thirst for knowledge is not quenched yet, here are some articles that might spark your interest!