APT is the short form of Advanced Package Tool. The APT is designed for managing the packages used in Linux distributions i.e., Debian. APT is free to use and has core tools for handling packages on Debian-based distributions. Ubuntu 22.04 is the latest LTS (Long Term Support) of Ubuntu (a widely used Debian-based distribution).
APT allows access to the Ubuntu packages repository with a one-liner command. With APT, one can perform many tasks such as installing, reinstalling, updating, upgrading and removing the packages.
The main objective of this article is to briefly describe the usage of apt package managers on Ubuntu 22.04 LTS.
How to Use APT Package Manager in Ubuntu 22.04 LTS
APT is an advanced tool for handling and managing Debian distributions’ packages. A number of tasks can be performed by using the apt package manager. This section lists the most used APT commands:
Note: In this article, we will use the “Sudoku” package as an example. Sudoku is a game available in the Ubuntu repository by default.
How to get the Cache status of the Ubuntu system using APT?
It will return the statistics about the system cache such as package, dependencies and libraries etc.
$ sudo apt-cache stats
The above command returned the total packages along with the number of dependencies and other package files etc.
How to List Down the Available Packages in Ubuntu using APT?
This command will return the list down all the package files in Ubuntu’s repository.
$ apt list
The above result shows that all the available packages are listed in ascending order i.e., 0-9 and a-z.
How to Display the Details of the Package in Ubuntu using APT?
This command will show detailed information about the package including source, dependencies, size, and description, etc.
$ sudo apt show sudoku
The above details in the terminal window displayed the detailed information of the package i.e. sudoku.
How to Search About the Package in Ubuntu using APT?
The search command is used to display matches of the package and find out whether the package is available or not.
$ sudo apt search sudoku
The above result shows that the word “sudoku” is available in the system.
How to Search the Package in APT Cache in Ubuntu using APT?
This command is also used for searching, but the difference is that it will return the package’s libraries and dependencies.
$ sudo apt-cache search sudoku
According to the above output, sudoku is available in the system cache.
How to Update System Files in Ubuntu using APT?
As the name implies, an update keeps the system’s core libraries, packages, and files up to date. It also displays the list of packages that need to be upgraded.
$ sudo apt update
The above screenshot shows that all package files and dependencies are updated.
How to Upgrade the System Packages/Core Libraries in Ubuntu using APT?
It is used to download the latest declaration files in the repository and merge them with existing packages.
$ sudo apt upgrade
How to Upgrade the Specific Package Only in Ubuntu using APT?
The –only-upgrade is used to upgrade the specific package, which is already available in the system. For instance, the following command will upgrade to the latest sudoku and install the latest version on Ubuntu 22.04 LTS.
$ sudo apt --only-upgrade install sudoku
The above screenshot shows that the sudoku package is the latest version, installed in the system.
How to Clean the Unnecessary Package in Ubuntu using APT?
This command is used for auto-cleaning the essentially useless files from the local repository. The auto-clean command also removes the files from the package which can no longer be downloaded. It keeps the cache cleared and maintained.
$ sudo apt autoclean
How to Fix the Broken Files of a Specific Package in Ubuntu using APT?
This command is very useful to fix the broken files of the installed packages.
$ sudo apt --fix-broken install
The output shows that there are no broken packages that need reinstallation.
How to Download the Package in Ubuntu using APT?
This command is used for downloading packages to local repository storage but without installing it. These files can be used later for the relevant task.
$ sudo apt download sudoku
How to install the Package in Ubuntu using APT?
This is the most commonly used command of the apt package manager. With apt install, new package files along with the relevant libraries and dependencies can be installed on Ubuntu 22.04.
$ sudo apt install sudoku
As per the above output, a new package “sudoku” is installed in the system.
How to Reinstall the Package in Ubuntu using APT?
If the dependencies and configuration files of a package are available, then we can install the package using the apt reinstall command. The following command will reinstall sudoku on Ubuntu 22.04:
$ sudo apt reinstall sudoku
The above output shows that the package has been reinstalled from the available configuration file.
How to Remove the Package from Ubuntu using APT?
This apt command is used to delete or remove the package but it keeps the configuration files and dependencies in local storage.
$ sudo apt remove sudoku
As shown in the above command output, the package is removed from the system.
How to Remove the Unnecessary Files Automatically from Ubuntu using APT?
During the installation of a package, some dependency files install automatically with the package but are now no longer needed. The “apt autoremove” command is used to delete those useless dependency files without marking them manually.
$ sudo apt autoremove sudoku
According to the above-mentioned output, the related files to the package have been removed from the system.
How to Remove the Package and Configuration Files from Ubuntu using APT?
While removing or deleting a package, the apt package manager keeps its configuration files for future use. The purge command is used for purging the package alongside its configuration files. The following command will remove the sudoku package and its configuration files as well:
$ sudo apt purge sudoku
From the above screenshot, it can be noticed in the last line that with the purge command the Configuration Files are also removed.
Here, you have learned the basic usage of the apt package manager on Ubuntu 22.04 LTS.
Conclusion
APT is a command-line utility mostly used for handling packages in Debian-based distributions. With the help of simple commands, APT simplifies the process of managing software including installation, deletion, and configuration on Ubuntu 22.04. There are a number of commands in the APT package manager but in this article, we have discussed the most commonly used commands.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY