APT (Advanced Package Tool) is the command line tool to interact with the packaging system. It helps in handling packages and retrieve the information and packages from the authenticated sources for installation, upgrade and removal of packages along with their dependencies. apt command is a more friendly way to handle packaging.
Mostly, to use apt command you requires superuser privileges so you’ll need to use sudo.
Update package index (apt update)
The APT package index is a database where it remember the available packages from the repositories which are enabled on your system.
apt actually works on a database of available packages. Without database update the system won’t know if there are any newer packages available.
On the updating the package index it will pull the latest changes from the repositories. Run the below command to update the package index:
sudo apt update
When you run this command, you’ll see the package information being retrieving from various servers.
Always remember that, you should update the package index before installing any new packages.
Upgrade Packages (apt upgrade)
Once you have updated the package database, you can now upgrade the installed packages.
Regularly updating your Linux system is one of the most important aspects of overall system security.
After updating the package database, you can now upgrade the installed packages. This is the most convenient way is to upgrade all the packages that have available updates. Simply use the command below:
sudo apt upgrade
This will show you how many and which all packages are going to be upgrade. Some packages requires removal of installed packages which will not upgrade.
You can upgrade specific package by passing package name as below:
sudo apt upgrade package_name
Install packages (apt install)
Install package is a easy same as single upgrade package. Run the below command to install any package:
sudo apt install package_name
You can install multiple packages at a single command just by passing a space-separated list:
sudo apt install package_name1 package_name2
Remove Packages (apt remove)
If you want to remove any package just execute the below command:
sudo apt remove package_name
Same as install, you can remove multiple packages in a single command, pass package names separated by spaces:
sudo apt remove package_name1 package_name2
After uninstalling package using remove some of package files may remain. If you would like to remove completely then you should use purge instead of remove:
sudo apt purge package_name
Remove Unused Packages
At the time of installation of any package some of dependencies are installed too. So when you uninstall some packages, the dependencies packages are remain on systems. These leftover packages are no longer use by anything else and can be remove.
remove the unused packages using:
sudo apt autoremove
Listing Packages (apt list)
You can use the
list command to get list of available, installed and upgradeable packages. Run the below command to get the list of available packages:
sudo apt list
If you need to find any specific package is installed or not you can use
grep along with list as below:
sudo apt list | grep package_name
Below command will return the list of only installed packages on your system:
sudo apt list --installed
To get the list of
upgradeable packages type:
sudo apt list --upgradeable
Package Information (apt show)
The information about the
package dependencies, installation size, the package source and so on might be useful before removing or installing a new package.
To retrieve information about a given package, use the show command:
sudo apt show package_name
Searching Packages (apt search)
You also can
search a package in the list of available packages:
sudo apt search package_name
If the command will found the nit will print the matched package name.
It is a good practice to have knowledge of manage packages.
If you have any query for installation of packages or any feedback, feel free to comment below.