The “apt-get” and “apt-cache” commands are very frequently used commands in the Linux environment. The former command mainly allows you to install, update, and remove packages, whereas the latter lets you search for packages and their related information. Both of these commands have their specific use cases, however, most of the users are not aware of their exact capabilities except for their basic usage. Therefore, today we have decided to share with you the twenty-three different examples where you can use “apt-get” and “apt-cache” commands to manage your system.

Fundamental apt-get Command Examples

The seventeen fundamental “apt-get” commands are described below.

Example 1: Update your Linux System

This is the most common usage of the “apt-get” command within the Linux environment since you need to update your system before installing any new application. At times, even before troubleshooting your system for any errors, you are required to update it so that any broken links or dependencies can be fixed beforehand.

To update your Linux system with the “apt-get” command, you need to run it in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-01.png" data-lazy- height="27" src="data:image/svg xml,” width=”406″>

Example 2: Upgrade your Linux System

After updating your system, you are presented with a message about the number of all those packages that can be upgraded, i.e., packages whose upgraded versions are available. Therefore, essentially the next step after updating your Linux system is to upgrade it, and this can be done by running the “apt-get” command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-02.png" data-lazy- height="29" src="data:image/svg xml,” width=”413″>

As compared to the “apt-get update” command, the “apt-get upgrade” command takes a longer time to execute as it has to install the upgraded versions of all those packages whose upgrades are available.

Example 3: Install a New Package on your Linux System

If you are a frequent computer user, then you have to install new packages on your system on a daily basis. You can also do this via the Linux GUI, however, if you prefer to use the CLI, then that is also possible.

You can conveniently install a new package on your Linux system by running the “apt-get” command in the following manner:

sudo apt-get install PackageName

Here, you have to replace the “PackageName” with the actual name of the package that you wish to install. We wanted to install the VLC media player for a demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-03.png" data-lazy- height="29" src="data:image/svg xml,” width=”443″>

Example 4: Delete a Package from your Linux System

When you have a large bulk of packages installed on your Linux system, then you would have seen the message of “storage space running out” very frequently. In this situation, the only solution you can come up with is to remove all the unused or irrelevant packages from your system.

This can easily be done by running the “apt-get” command in the following manner:

sudo apt-get remove PackageName

Here, you have to replace the “PackageName” with the actual name of the package that you wish to remove. We wanted to remove the VLC media player for a demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-04.png" data-lazy- height="24" src="data:image/svg xml,” width=”436″>

Example 5: Delete a Package along with its Configuration Files from your Linux System

The simple “apt-get remove” command merely removes the specified package from your Linux system. However, the configuration files of that package still reside on your system. If you also want to get rid of those configuration files along with the desired package, then you can run the “apt-get” command in the following manner:

sudo apt-get purge PackageName

Here, you have to replace the “PackageName” with the actual name of the package that you wish to remove, along with its configuration files. We wanted to remove the VLC media player for demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-05.png" data-lazy- height="28" src="data:image/svg xml,” width=”427″>

Example 6: Delete all the Dependencies of a Deleted Package from your Linux System

At times, a single package on Linux requires multiple other packages to function properly. These packages are known as the dependencies of the said package, and they are installed along with that package. However, when you remove a package, either with the “apt-get remove” command or with the “apt-get purge” command, these dependencies are not removed automatically. Therefore, to remove these unused dependencies for freeing up your system’s space, you can run the “apt-get” command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-06.png" data-lazy- height="25" src="data:image/svg xml,” width=”434″>

This command will explore your whole Linux system in search of all those packages and dependencies that are no longer needed and will remove them altogether.

Example 7: Smartly Upgrade your Linux System

The simple “apt-get upgrade” command upgrades all the available packages on your Linux system without even checking if upgrading a particular package is required or not. If you want to perform the up-gradation process smartly, then you can run the “apt-get” command in the following manner:

sudo apt-get dist-upgrade

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-07.png" data-lazy- height="29" src="data:image/svg xml,” width=”447″>

Another feature of this command is that it not only upgrades the packages smartly but also removes those packages and dependencies that are no longer needed.

Example 8: Perform a Linux System Clean up

If you want to clean up all the temporary files from your Linux system, then you can use the “apt-get” command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-08.png" data-lazy- height="25" src="data:image/svg xml,” width=”395″>

This command will remove all the temporary files from your Linux system, hence freeing up your disk space.

Example 9: Find out the Changes in a Package by Checking the Log

Whenever you install an application or a package on your Linux system and start using it, you make certain changes to it. If you want to take a look at all those changes before you upgrade any desired package, then you can run the “apt-get” command in the following manner:

sudo apt-get changelog PackageName

Here, you have to replace the “PackageName” with the actual name of the package whose changelog you want to view before upgrading it. We wanted to view the changelog of the VLC media player for demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-09.png" data-lazy- height="29" src="data:image/svg xml,” width=”457″>

Example 10: Clean all your Linux System’s Local Repository Packages

At times, some .deb files keep residing in your Linux system’s local repository even if they are no longer installed. That is why it is always recommended to get rid of these files as soon as possible to reclaim your disk space.

To clean all your Linux system’s local repository packages, you can run the “apt-get” command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-10.png" data-lazy- height="28" src="data:image/svg xml,” width=”428″>

Example 11: Download a Package on your Linux System

Sometimes, you only wish to download a package on your Linux system without installing it. This may be required when you need to install this package at a later time or if you want to keep a downloaded backup copy of a particular package. Therefore, to download a package on your Linux system without installing it, you can run the “apt-get” command in the following manner:

sudo apt-get download PackageName

Here, you have to replace the “PackageName” with the actual name of the package that you want to download without installing it on your Linux system. We wanted to download the VLC media player for demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-11.png" data-lazy- height="30" src="data:image/svg xml,” width=”454″>

Example 12: Look for Broken Packages or Dependencies on your Linux System

At times, some installed dependencies or packages on your Linux system might get corrupted. We refer to such packages or dependencies as “broken”. Therefore, if you wish to find out all the broken packages or dependencies on your Linux system, then you can run the “apt-get” command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-12.png" data-lazy- height="26" src="data:image/svg xml,” width=”396″>

Example 13: Fix the Broken Packages or Dependencies on your Linux System

Once you have found out all the broken packages or dependencies on your Linux system, the next step is to fix them all, so you can easily proceed with further installations.

You can fix all your broken packages or dependencies on your Linux system by running the “apt-get” command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-13.png" data-lazy- height="30" src="data:image/svg xml,” width=”435″>

Example 14: Access the Manual Pages of the “apt-get” Command

If you ever wish to know more details about the “apt-get” command, then you can access its man pages in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-14.png" data-lazy- height="28" src="data:image/svg xml,” width=”340″>

Example 15: Access the Help Pages of the “apt-get” Command

If you want to know the syntax and options that are available for the “apt-get” command, then you can access its help pages for this purpose.

To access the help pages of the “apt-get” command, you can run this command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-15.png" data-lazy- height="28" src="data:image/svg xml,” width=”364″>

Example 16: Reinstall a Package on your Linux System

Sometimes, an installed package on your Linux system might not be performing correctly. Such issues can arise for several reasons, out of which the most important reason is its improper installation. In such a situation, you might think of reinstalling an already installed package.

This can be done by running the “apt-get” command in the following manner:

sudo apt-get install –reinstall PackageName

Here, you have to replace the “PackageName” with the actual name of the package that you want to reinstall on your Linux system. We wanted to reinstall the VLC media player for demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-16.png" data-lazy- height="31" src="data:image/svg xml,” width=”539″>

Example 17: Download the Source Code of a Package on your Linux System

If you just wish to download the source code of a package without installing it on your Linux system, then you can run the “apt-get” command in the following manner:

sudo apt-get –download-only source PackageName

Here, you have to replace the “PackageName” with the actual name of the package whose source code you want to download without installing it on your Linux system. We wanted to download the source code of the VLC media player for a demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-17.png" data-lazy- height="27" src="data:image/svg xml,” width=”563″>

Fundamental apt-cache Command Examples

The six fundamental “apt-get” commands are described below.

Example 18: List all the Available Packages on your Linux System

Generally, when you start using a Linux based system, initially, you are clueless about which packages you essentially need to install. At times, you are not even aware of the exact package names. Therefore, it is always considered very helpful if you can somehow list down all the installable packages.

To list all the available packages on your Linux system, you can use the “apt-cache” command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-18.png" data-lazy- height="30" src="data:image/svg xml,” width=”437″>

This command will list down the names of all the packages that are available for your Linux system.

Example 19: List the Detailed Information about a Package on your Linux System

At times, you might want to know all the details regarding a particular package for the sake of knowing its compatibility and other stuff like that.

To list the detailed information about a package on your Linux system, you can run the “apt-cache” command in the following manner:

sudo apt-cache showpkg PackageName

Here, you have to replace the “PackageName” with the actual name of the package whose detailed information you want to list down on your Linux system. We wanted to list down the detailed information about the VLC media player for demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-19a.png" data-lazy- height="27" src="data:image/svg xml,” width=”459″>

Example 20: List all the Basic Information about a Package on your Linux System

The above-mentioned command list down all the possible details about any particular package. However, if you only wish to list down the basic information about a package, then you can run the “apt-cache” command in the following manner:

sudo apt-cache show PackageName

Here, you have to replace the “PackageName” with the actual name of the package whose basic information you want to list down on your Linux system. We wanted to list down the basic information about the VLC media player for a demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-19.png" data-lazy- height="27" src="data:image/svg xml,” width=”441″>

Example 21: Search for some Specific Packages via Keyword Search on your Linux System

Sometimes, you do not remember the exact name of a package, but you still wish to search for it. All you remember is a specific keyword that is a part of the name of your package. In this scenario, you can still perform a keyword search to look for all those packages, which contain the specified keyword.

To do this, you can run the “apt-cache” command in the following manner:

sudo apt-cache search “Keyword”

Here, you have to replace the “Keyword” with the actual keyword contained in the name of the package that you want to look for on your Linux system. We wanted to search for all those packages that contain the “server” keyword in their names for demonstration, which is why we have replaced the “Keyword” with the “server”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-20.png" data-lazy- height="29" src="data:image/svg xml,” width=”500″>

Example 22: Search for a Specific Package by Mentioning its Name on your Linux System

If you remember the exact name of a package, then you can simply look for it on your Linux system by mentioning its exact name.

You can search for a specific package on your Linux system by running the “apt-cache” command in the following manner:

sudo apt-cache search PackageName

Here, you have to replace the “PackageName” with the actual name of the package that you want to look for on your Linux system. We wanted to search for the VLC media player for a demonstration, which is why we have replaced the “PackageName” with “vlc”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-21.png" data-lazy- height="26" src="data:image/svg xml,” width=”452″>

Example 23: List Cache Statistics on your Linux System

If you wish to know the overall cache statistics of your Linux system, i.e., the total number of packages, types of packages, etc. then you can run the “apt-cache” command in the following manner:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/23-fundamental-apt-get-and-apt-cache-commands-you-need-to-manage-your-system-22.png" data-lazy- height="28" src="data:image/svg xml,” width=”413″>

Conclusion

In this article, we provided you with a very detailed tutorial on the usage of the “apt-get” and “apt-cache” commands. Most of the users are familiar with the “apt-get” command, but they do not have any clue about the usage of the “apt-cache” command. After going through this tutorial, they will be in a very good position to use the “apt-cache” command as smoothly as they would have used any other basic Linux command. Moreover, the usage of the “apt-get” command is also explained in-depth in this article, as seventeen out of our twenty-three examples were dedicated to this purpose. That is why, after going through this article, anyone can master the usage of the “apt-get” and “apt-cache” commands.

About the author

<img alt="Karim Buzdar" data-lazy-src="https://kirelos.com/wp-content/uploads/2020/12/echo/karim-150×150.png" height="112" src="data:image/svg xml,” width=”112″>

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.