apt Command in Linux | Explained

The advance packet manager or the apt command is used to handle different functionalities that your Debian-based Linux (OS) has to offer. Some of them are installing any new package or upgrading the already installed packages in your OS.

Linux (OS) comes with different repositories such as main, universe, restricted, and multiverse. The role of the apt command is to fetch the required information from them that you are looking for. The content that describes the usages of the apt command is as follows:

Let’s start from the first one.

Update Core Libraries | apt update

The apt update command is used to fetch the information of all the packages installed in your Linux (OS), and then it will provide you with a number that you can upgrade. Simultaneously, it updates the core libraries of your Debian system (packages list) by typing:

$ sudo apt update

As you can see in the above image, there is a total of 120 packages that you can upgrade, so it is always recommended to run this command frequently.

Upgrade Packages | apt upgrade

The upgrade command will automatically upgrade all the packages that can be upgraded to their latest version by typing:

$ sudo apt upgrade

If you want to upgrade the whole system, then you can do that as well by typing the below command:

$ sudo apt full-upgrade

If you want to see the list of all those packages that can be upgraded then you need to run the following command:

$ sudo apt list --upgradeable   

List the Packages | apt list

You can see the list of all available packages that are available for your system by typing the below command:

$ sudo apt list

If you want to see the list of all those packages that are already installed in your system, then you can do that by typing the command:

$ sudo apt list --installed

Show Package Details | apt show

This command will show you additional information regarding any application by typing:

$ sudo apt show vim

Install Packages | apt install

You can install any package that is available in the apt repository by following the syntax:

$ sudo apt install [Package Name]      

Let’s suppose you want to install the ‘vim’ so you can do that by following the below command:

$ sudo apt install vim   

Sometimes while installing any package, you need to provide the authentication password so to avoid that

Remove Packages | apt remove

Similarly, if you want to remove any package from your system using the apt command, then the following syntax is used:

$ sudo apt remove [Package Name]

For instance, to remove vim, use the below-stated command:

$ sudo apt remove vim

The below-mentioned command will remove not only the applications but also the packages associated with them:

$ sudo apt purge vim

Remove Unused Packages | apt autoremove

Sometimes a package that you are planning to install depends on other packages and won’t function properly without them. So, you need to install those as well, but once you delete any package, the dependencies still reside in your OS. So, to delete such leftover packages, you can run the following command:

$ sudo apt autoremove

Clear Cache | apt clean

The clean command is responsible for clearing the cache memory of the apt manager so that you can utilize that memory somewhere else by typing:

$ sudo apt clean

That’s all from this post.

Conclusion

Advanced packet manager (apt) is a powerful command-line tool that installs and upgrades software packages. The apt command is associated with the Debian-based distributions on Linux. This post has briefly explained the purpose and all the possible usages of the apt command in Linux.