In a debian based package management system the
apt-cache is a low-level tool to manipulate and obtain information about packages from apt’s internal database. It creates a repository of information about the packages that are available from your source list. Apt’s database gets updated when you run
apt update command.
Let’s say you want to install the Google Chrome web browser from your terminal but you don’t know the exact name of the package that can be used to install it. First, open your terminal by using
ctrl+alt+t and then execute the following command –
sudo apt-cache search google-chrome
And this would return a list of packages available that refer to the word google-chrome. Now you can choose the right one to install in your system.
What are other operations that can be performed with apt-cache?
apt-cache you can perform various operations on apt’s internal database some of them are given below-
apt-cache showsrc package-name
To display all the source package records that match with the given package name use the above command
apt-cache showpkg package-name
To display the information for packages listed on the command line it will show dependencies, reverse dependencies, etc
To display the statics of cache it includes information such as total package name, total package structure, etc execute the above command
No further arguments are required with this command
To display information of cache in the terse form use the above command
The above command will display all unmet dependencies of packages
You can also check it for a specific package by adding the package name as the argument to this command.
apt-cache show package-name
To display the readable record for a given package use the above command
apt-cache search package-name
As discussed above to search the exact name of a package use the search command as given below
It will search and display a list of packages matching with the given pattern
apt-cache depends package-name
To display all the dependencies a package has and all the other package that can fulfill those dependencies
apt-cache rdepends package-name
To display all the reverse dependencies that a package has, execute the above command
To display the name of all packages that apt know execute the above command
apt-cache dotty package-name
Use the above command to find the co-relation and dependency between different packages.
The dotty takes a list of packages in the command line and generate package graphs that are used by dotty from Graphviz. The output of this command will be a set of nodes and edges representing the relationship between the packages.
Is there any other way to find the exact name of a package?
Apart from using
apt-cache, you can also use the aptitude command to find the exact name of a package. It will display a list of packages containing the given pattern. We will again search for the same package i.e. a web browser program as we do with
apt-cache command. Execute the following command in your terminal-
aptitude search google-chrome
Now, look at the screenshot given below-
On the left column of the response we have got, you see i, p, etc. where i indicates the programs that are already installed in the system and p represents the programs that are available for installation.
Well, this is the benefit of using aptitude which gives the information of whether a program is installed or not. But comparatively, it is slower than the
apt-cache search command.
Now if you know any other way to do so or if you have a query or suggestion on improving this topic then let us know by writing in the comments section.