APT is an abbreviation for Advanced Package Tool. It is used for downloading, removing, or upgrading software packages. APT is a powerful tool that can also be used with sudo, which lets us be the super user or sudo root user. In this article, you will get to know all the aspects and features of APT in Linux.
How to Use APT in Linux
APT must be used with sudo. Because to install, remove or upgrade you need to be root users. As you know sudo gives the root privilege.
You can use apt in multiple ways, for various purposes. For example Installation, update, or removal of packages. Now we will look at some ways we can use APT.
How to Install Packages Using APT in Linux
Let’s say you want to view the calendar on our machine. You write the command below:
ncal
This should give you the calendar of the running month. The terminal should show-But if you didn’t install ncal on our machine, you will have to install ncal. No need to worry, I will show you how to resolve this problem.
Steps to Follow >
➊ Open your Ubuntu terminal.
➋ Write the following commands and press ENTER.
sudo apt install ncal
You will have to give the password. Don’t worry it’s just your user password, not the root user password.➌ Provide the password and you will see the installation start.
Now I have already installed ncal so my machine didn’t install anything new. But yours will surely install ncal. You can install all the required software packages this way. There you go, you have mastered how to install software packages using APT.
Bonus: If you want to install multiple packages at a time execute the command.
sudo apt install pack1 pack2
How to Remove Packages Using APT
Now removing software packages isn’t something you do often. But it is important to know the command lines for that. Now, this too can be done using APT. Let’s say you want to get rid of ncal. For this, follow the steps below.
Steps to follow >
➊ Open the Ubuntu terminal.
➋ Write the commands below and press ENTER.
sudo apt remove ncal
➌ Now it will ask you if you want to delete it or not. Press yOutput >
➍ ncal is removed.
Congratulations, you now know how to install and remove individual software packages using sudo apt command.
Now you can also use –purge. In this way, you can remove the package and the configuration files too. So be cautious while using -purge
sudo apt purge package
Bonus: If you want to remove multiple packages at a time execute the command.
sudo apt remove pack1 pack2
Autoremove
While doing various command line operations there are some software packages that are installed by-products of those operations. After completing the operation you don’t really need these packages, so you delete them using autoremove.
Steps to Follow >
➊ Open the Ubuntu terminal.
➋ Write the commands and press ENTER.
sudo apt autoremove
➌ Now it will ask you if you want to delete it or not. Press yOutput >
How to Update Packages Using apt in Linux
Now if you want to make all the available packages up to date, we can use the update option.
Now follow the steps below.
Steps to Follow >
➊ Open the Ubuntu terminal.
➋ Write the commands and press ENTER.
sudo apt update
➌ Provide the password and you will see that update started.Output >
Now there might be times when you need to upgrade your system rather than update. First, you will run an update, then the terminal will tell you if there is anything to update. You can see the list of upgrades using list.
Steps to Follow >
➊ Open the Ubuntu terminal.
➋ Write the commands and press ENTER.
sudo apt list --upgradable
Output >You will have this list printed out on our terminal. Now how to upgrade them? No worries, I will discuss that in the next section.
How to Upgrade Using apt in Linux
To upgrade I do need root permission. So I must use sudo for enabling my root user privilege. Now there are two options, I can upgrade all the available packages or I can upgrade each package individually. I will show you both the options.
Steps to Follow >
➊ Open the Ubuntu terminal.
➋ Write the commands and press ENTER.
- Upgrade all the packages:
sudo apt upgrade
This will start upgrading all the existing packages in the system.
- Upgrade a specific package:
sudo apt upgrade package_name
This will start upgrading that specific package. The terminal should look like the image below.Now I see that it asks for permission if I want to upgrade or not. I will press y for Yes n for No.
Bonus: If you want to directly upgrade without being asked, you use the commands below.
sudo apt -y upgrade
Upgrade vs Full Upgrade
First of all, the syntax for these commands is different. For upgrade, you will use
sudo apt upgrade
and for full-upgrade, you use
sudo apt full-upgrade
Secondly, these two commands function a little differently. The core difference between upgrade and full-upgrade– the latter will remove any pre-installed packages to upgrade the entire system if needed. So we must be very cautious while using full-upgrade.
Printing Lists with apt
Now you have already seen this example above when I listed out my upgradable software packages. But you have to remember that you can print out a list of any packages that are inside your machine. In this section, I will give an example.
sudo apt list --installed.
This will give me a list of all the packages that are installed in my system. Let’s take a look at the sample output below.
Output >
Searching Using apt
You can do a search on your system using apt. What it does is looks for matching package names within the machine’s existing package.
Steps to Follow >
➊ Open the Ubuntu terminal.
➋ Write the commands and press ENTER.
sudo apt search ncal
➌ Provide the user password if it’s already been 15 minutes since your last sudo session.
Output >
Using apt to Show Information about a Package
If you want to know how much space a package is holding. Or if you wanted to know about the source of a package, you can do that using show. So for that look below.
Steps to Follow >
➊ Open your Ubuntu terminal.
➋ Write the command and press ENTER.
sudo apt show ncal
➌ Provide the password (user password)
Output >
This shows all the relevant data about ncal
Some Advanced Use of apt (Combined Commands)
Let’s say you want to update and upgrade together rather than first updating and then upgrading. You can use Logical Operation. Does it sound difficult? If it does then don’t worry just follow me step by step.
Steps to Follow >
➊ Open your Ubuntu terminal.
➋ Write the commands and press ENTER.
sudo apt update && sudo apt upgrade
➌ Provide the password (user password)Output >
Let’s Look at Another Advanced Use
Here you will separate ncal from all the installed packages.
Steps to Follow >
➊ Open your Ubuntu terminal.
➋ Write the commands and press ENTER.
sudo apt list | grep ncal
➌ Provide the password (user password)Output >
apt vs apt-get
apt is a better and newer version of apt-get. apt brought some key improvements in command line execution and also in terminal output.
Detailed output
apt gives more detailed output than apt-get. Let’s take a look at the image below
Improved Designed Output
apt provided users with better-looking terminal output compared to apt-get. Now, look at the picture you should have a clear idea.
New Commands
apt came with some new commands which don’t work with apt-get. For example:
➊ list doesn’t work with apt-get.
➋ edit-sources doesn’t work with apt-get.
apt Command Not Found in Linux
By now you should know what apt does. It has the ability to install, remove, update, or upgrade software packages into Linux Distribution. But this only works with Ubuntu, Debian and its derivatives.
So this error occurs when we try to install operating systems that are not compatible with apt, like Fedora, MacOS X etc.
How to resolve apt command not found problem
➊ One way to solve this problem is to use Linux Distribution that is compatible with apt.
➋ Install the latest apt package.
➌ Use apt with appropriate operating systems.
Conclusion
In this article, I have tried to explain how apt works, some useful command lines, and the difference between apt and apt-get. I tried to make it as simple as possible, considering how hard it is to learn to use the command line for beginners. So after reading this article you should be able to use apt properly and without facing many difficulties.
So if you found the above article helpful then check out Alias. This will help you further master the Linux command line.
Similar Readings