In the next article we are going to take a look at how we can search for available packages from the command line. There are several ways to search for packages available in Debian, Ubuntu, or Linux Mint from the terminal. These packages can be search thanks to apt, apt-cache y aptitude. These tools will help us when looking for package names and descriptions of these. They can also be very useful if we are looking for a specific package but we do not know the exact name of the package or if we need a tool for a particular purpose or task. This way we will be able to know the available options.
The main differences between using apt, apt-cache and aptitude to search for available packages are their output and the order in which these packages are classified. Also, aptitude may not be installed by default on your Debian-based Gnu / Linux distribution. If this is your case, you will have to install it.
Of all the examples that we are going to see, apt-cache has the easiest to read output since normally I don't need additional information. To see the installed / available versions you can use the apt-cache policy package name.
Another thing to keep in mind is that apt and apt-cache search the cache of apt software packages, so they return both the packages available in the repositories such as manually installed DEB packages (not available in repositories). In the case of aptitude, it will only return the packages that are available in the repositories.
Search for available packages from the command line
Search for available packages using apt-cache
As I have already written, we can use apt-cache to search for available packages in the Debian, Ubuntu, or Linux Mint repositories, in addition to the installed DEB packages that are not in the repositories. The format to use would be the following:
apt-cache search BÚSQUEDA
A practical example of search for package "nodejs" it would be something like the following:
apt-cache search nodejs
As you can see in the previous capture, I have not been able to capture all the output, because it can be very long.
Search for available packages using aptitude
In the case of aptitude, this is a Ncurses-based front-end for apt. This tool is generally not installed by default, but we will be able to install it on Debian, Ubuntu, Linux Mint and other Debian-based Gnu / Linux distributions using this command in a terminal (Ctrl + Alt + T):
sudo apt install aptitude
After installation, we will be able to use aptitude to search for packages from the command line. The format to use will be something like this:
aptitude search BÚSQUEDA
A practical example to find the package "nodejs" would be the following:
aptitude search nodejs
We will also be able to use the aptitude Ncurses user interface. We will not have more to write aptitude to start it:
Here we can search for packages by pressing / and then typing the keyword for search.
Search for available packages using apt
Using apt, we can search for available packages from the command line as follows:
apt search BÚSQUEDA
Just have to replace the word SEARCH with the keyword that we are interested in looking for. We can add several keywords in quotes.
This would be an example of searching for 'nodejs' along with its output:
apt search nodejs
Once again, the results are so many that it has been impossible for me to capture them all in the previous image.
Make the results easier to read
In the three cases we have just seen, the search results can be very long. When it is so, we will be able to run them using more next to the commands. This will make it easier to read, as shown below:
apt-cache search BÚSQUEDA | more
We can also exclude results that don't include a particular keyword (SEARCH2 in this example) using grep:
apt-cache search BÚSQUEDA | grep BÚSQUEDA2
Grep is case sensitive by default. If we add the -i option we can ignore the upper and lower case. It would be as follows: grep -i SEARCH2.