25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management

Standard

This article explains how quickly you can learn to install, remove, update and search software packages using apt-get and apt-cache commands from the command line. This article provides some useful commands that will help you to handle package management in Debian/Ubuntubased systems.

APT-GET and APT-CACHE Commands

APT-GET and APT-CACHE Commands

What is apt-get?

The apt-get utility is a powerful and free package management command line program, that is used to work with Ubuntu’s APT (Advanced Packaging Tool) library to perform installation of new software packages, removing existing software packages, upgrading of existing software packages and even used to upgrading the entire operating system.

What is apt-cache?

The apt-cache command line tool is used for searching apt software package cache. In simple words, this tool is used to search software packages, collects information of packages and also used to search for what available packages are ready for installation on Debian or Ubuntu based systems.

APT-CACHE – 5 Useful Basic Commands

1. How Do I List All Available Packages?

To list all the available packages, type the following command.

2. How Do I Find Out Package Name and Description of Software?

To find out the package name and with it description before installing, use the ‘search‘ flag. Using “search” with apt-cache will display a list of matched packages with short description. Let’s say you would like to find out description of package ‘vsftpd‘, then command would be.

To find and list down all the packages starting with ‘vsftpd‘, you could use the following command.

3. How Do I Check Package Information?

For example, if you would like to check information of package along with it short description say (version number, check sums, size, installed size, category etc). Use ‘show‘ sub command as shown below.

4. How Do I Check Dependencies for Specific Packages?

Use the ‘showpkg‘ sub command to check the dependencies for particular software packages. whether those dependencies packages are installed or not. For example, use the ‘showpkg‘ command along with package-name.

5. How Do I Check statistics of Cache

The ‘stats‘ sub command will display overall statistics about the cache. For example, the following command will display Total package names is the number of packages have found in the cache.

APT-GET – 20 Useful Basic Commands for Package Management

6. How to Update System Packages

The ‘update‘ command is used to resynchronize the package index files from the their sources specified in /etc/apt/sources.list file. The update command fetched the packages from their locations and update the packages to newer version.

7. How to Upgrade Software Packages

The ‘upgrade‘ command is used to upgrade all the currently installed software packages on the system. Under any circumstances currently installed packages are not removed or packages which are not already installed neither retrieved and installed to satisfy upgrade dependencies.

However, if you want to upgrade, unconcerned of whether software packages will be added or removed to fulfill dependencies, use the ‘dist-upgrade‘ sub command.

8. How Do I Install or Upgrade Specific Packages?

The ‘install‘ sub command is tracked by one or more packages wish for installation or upgrading.

9. How I can Install Multiple Packages?

You can add more than one package name along with the command in order to install multiple packages at the same time. For example, the following command will install packages ‘nethogs‘ and ‘goaccess‘.

10. How to Install Several Packages using Wildcard

With the help of regular expression you can add several packages with one string. For example, we use * wildcard to install several packages that contains the ‘*name*‘ string, name would be ‘package-name’.

11. How to install Packages without Upgrading

Using sub ‘–no-upgrade‘ command will prevent already installed packages from upgrading.

12. How to Upgrade Only Specific Packages

The ‘–only-upgrade‘ command do not install new packages but it only upgrade the already installed packages and disables new installation of packages.

13. How Do I Install Specific Package Version?

Let’s say you wish to install only specific version of packages, simply use the ‘=‘ with the package-name and append desired version.

14. How Do I Remove Packages Without Configuration

To un-install software packages without removing their configuration files (for later re-use the same configuration). Use the ‘remove‘ command as shown.

15. How Do I Completely Remove Packages

To remove software packages including their configuration files, use the ‘purge‘ sub command as shown below.

Alternatively, you can combine both the commands together as shown below.

16. How I Can Clean Up Disk Space

The ‘clean‘ command is used to free up the disk space by cleaning retrieved (downloaded) .debfiles (packages) from the local repository.

17. How Do I Download Only Source Code of Package

To download only source code of particular package, use the option ‘–download-only source‘ with ‘package-name’ as shown.

18. How Can I Download and Unpack a Package

To download and unpack source code of a package to a specific directory, type the following command.

19. How Can I Download, Unpack and Compile a Package

You can also download, unpack and compile the source code at the same time, using option ‘–compile‘ as shown below.

20. How Do I Download a Package Without Installing

Using ‘download‘ option, you can download any given package without installing it. For example, the following command will only download ‘nethogs‘ package to current working directory.

21. How Do I Check Change Log of Package?

The ‘changelog‘ flag downloads a package change-log and shows the package version that is installed.

22. How Do I Check Broken Dependencies?

The ‘check‘ command is a diagnostic tool. It used to update package cache and checks for broken dependencies.

23. How Do I Search and Build Dependencies?

This ‘build-dep‘ command searches the local repositories in the system and install the build dependencies for package. If the package does not exists in the local repository it will return an error code.

24. How I Can Auto clean Apt-Get Cache?

The ‘autoclean‘ command deletes all .deb files from /var/cache/apt/archives to free-up significant volume of disk space.

25. How I Can Auto remove Installed Packages?

The ‘autoremove‘ sub command is used to auto remove packages that were certainly installed to satisfy dependencies for other packages and but they were now no longer required. For example, the following command will remove an installed package with its dependencies.

I’ve covered most of the available options with apt-get and apt-cache commands, but still there are more options available, you can check them out using ‘man apt-get‘ or ‘man apt-cache‘ from the terminal. I hope you enjoyed reading this article, If I’ve missed anything and you would like me to add to the list. Please feel free to mention in the comment below.

Source: http://www.tecmint.com/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management/

Leave a Reply

Your email address will not be published. Required fields are marked *

28 + = 36