You reading this post means you new to the Linux world. So, till now, you have frequently heard this apt term if you were using Debian-based distribution like Ubuntu, Mint, or PopOS. Like you have to use apt to install any package or use apt to remove any packages in this distribution.
So, Today we going to see all different usage of apt Command in practical with proper examples.
What is apt?
Debian based distribution use dpkg packaging system to provide application or programs for installation. If you think, what if this packaging system doesn’t exist. Then, we have to compile and install all of those packages we want, which is not a good idea.
APT (Advanced Package Tool), which combines old apt-get and apt-cache command, provides us with an interactive and simple way to deal with Debian packages like installing, removing, upgrading, etc.
But remember, most of the time, when you install packages using the apt command, you require to be a root user or user with SUDO privileges.
Updating package database with apt
On other platforms, when you have to upgrade any packages or software, you directly hit the upgrade button to update. But in Linux, the story is quite different here; everything works based on the database.
In the database, all package version is available where you have to update those packages you have to first upgrade your database with a new version of those packages.
$ sudo apt update
So, if any update is available for those packages, it will be reflected in your database, and the next time you upgrade your system, it will upgrade those packages.
Make sure to always update index or database before upgrading or installing new packages.
Upgrade packages with apt
Regularly updating your system with the latest package and patches is good for overall system health and security.
Once you updated your index or database now, you can easily upgrade all of the packages in your system to the latest.
$ sudo apt upgrade
Remember this command don’t upgrade the installed packages, which require the removal of other packages.
If you want to upgrade a single package or application, specify the package name after the upgrade.
$ sudo apt upgrade <package-name>
If there is no upgrade available for that package in the database then it don’t perform anything.
Full system upgrade with apt
The difference between upgrade and full-upgrade is in full upgrade all packages which require removal of other packages.
$ sudo apt full-upgrade
Always backup your system before doing a complete backup. If any package is removed and caused system booting failure, you can easily recover.
Installing packages with apt
Now here the advantage of using apt comes. Installing new packages is simple like shown below.
$ sudo install <package-name>
It simply installs that package if it is available in your system added repository at /etc/apt/source.list. If the package is already installed, it doesn’t touch anything.
You can even install multiple packages at the same time. Just separate each package with space.
$ sudo install <package-one> <package-two> <package-three>
Now there is two different way to remove packages installed in your system. 1. Remove packages but want to keep configuration file.
So, in the future, if you install those packages again, then you don’t have to configure them again.
$ sudo apt remove <package-name>
2. Remove the package with its configuration files means removing the complete package.
$ sudo apt purge <package-name>
When you install packages in your system, it installs some other packages and libraries with it for dependencies support. When you remove those packages, then these dependencies leftover which does not require anymore.
So, to remove unused dependencies, use the following command.
$ sudo apt autoremove
Listing packages with apt
The list command helps to list all available packages, installed packages, and packages that need to be upgraded in your system.
To list every information use the following command.
$ sudo apt list
Now this command list information of package with version name. To search specific packages in your system, you can filter out them using the grep command.
$ sudo apt list | grep <package-name>
To list only installed packages in your system use the following command.
$ sudo apt list --installed
Listing only upgradable packages in your system is really useful before upgrading our system.
$ sudo apt list --upgradeable
Searching packages with apt
If you want to install any packages but don’t know the exact name of that package. You can use an apt search to find the package name by just providing some string to describe that package.
$ sudo apt search <package-name>
If any thing match the name it will out it with the package name and version available.
Package information with apt
Retrieving information about package version, source, maintainer, download size, dependencies depends on that package, and description before installing new packages can be helpful.
To retrieve all this information use the following command.
$ sudo apt show <package-name>
Know about distribution packages is really helpful. If you want to dig down more about apt, use man apt to know more information about apt.
If you have any queries feel free to ask in the commend section.
Innovative tech mind with 10 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.