Have you ever struggled while searching packages via the command line on Ubuntu? Have you ever searched for packages that require an instant upgrade? Ever wonder if the package you want to download is available to install, and is the latest version available in the software repository?

Searching for installed or uninstalled packages inside the local repositories via the terminal can be a daunting task for beginner Ubuntu users. This article answers all and many of the similar questions. Besides, we will also cover alternative ways to search for packages on Ubuntu and help you find a suitable method.

Ways to Search for Packages in Ubuntu

Here we'll cover three ways to perform package search on Ubuntu. However, before beginning, launch the terminal and update your system's package repositories by running:

        sudo apt update
    

Using the apt Command

APT is a command-line package manager that comes preinstalled on Ubuntu, Linux Mint, and other Debian-based distributions. The apt command combines the functionality of apt-cache and apt-get. It is responsible for installing, removing, updating, and upgrading packages and Linux repositories on Ubuntu. However, it also lets you search for packages.

You can begin by listing all the available installed/uninstalled packages on your system, as follows:

        apt list
    

Output:

apt list

You can pipe the above command with grep to filter the output and get a package name of your choice.

        apt list | grep <package_name>
    
apt list mysql example

Use the apt list command with the --installed option to only find and display the installed packages on your system.

        apt list --installed
    

Moreover, the list method also allows you to search a package and figure out if it is installed or not using the -a flag, as follows:

        apt list -a <package_name>
    

Output:

apt list installed

To search and display all the packages that require an upgrade:

        apt list --upgradeable
    

Use the grep utility if you are looking for a specific package in this list:

        apt list --upgradeable | grep <package_name>
    

However, the above commands do not display package details. The dedicated commands apt-search and apt show help find and display the available package details in the Linux terminal.

The apt search command is known for displaying package details in a better format. The best thing about this command is that it tells the user if a package is already installed or not with brief information about the available versions and description, etc.

For instance, the command below looks for the mysql package by searching all the package name strings and their description. Hence, it returns the list of packages containing that package name string in its name and description:

        apt search mysql
    

Output:

apt search mysql

To limit the search result, you can tell the command to only look for the given package name by providing the --name-only option as follows:

        apt search --name-only <package_name>
    

The apt show command displays more detail about the given package name. The package description contains details about its latest version release, dependencies, download size, repository information, etc. Most importantly, the command returns an exact package name such that you don't have to make guesses in figuring out the package you are looking for.

        apt show <package_name>
apt show mysql-client-core-5.7 | less
apt show mysql

Using the apt-cache Command

apt-cache is a command-line utility that queries packages from the local package lists file stored in /var/lib/apt. The system updates these files whenever the user runs the apt update command in the terminal. Hence, whenever the user searches for a package using the command, it does not need to access the network to fetch information from the repositories.

It is an older version of APT that you can use with the search and show options to find the packages.

        apt-cache search apache2
    

Output:

apt cache search apache2

The command also allows you to list all the packages that begin with the given keyword:

        apt-cache pkgnames <keyword>
    

For example:

apt cache pkgname apache2

To display all available packages with no detail:

        apt-cache pkgnames
    

You can also pipe the above command with the grep utility and use the -i flag to ignore case sensitivity and fetch the packages.

        apt-cache pkgnames | grep -i <keyword>
    

The utility also lets you search for packages and display their dependencies, whether they are installed on the system or not, as follows:

        apt-cache showpkg apache2
    

Output:

apt cache showpkg

You can notice that apt-cache search and apt-cache show is similar to apt search and show methods in terms of package information display. However, apt-cache and apt significantly differ in terms of data representation.

Using aptitude

aptitude is a graphical user interface for the APT package manager. The interface allows users to interactively choose packages to install, remove, and upgrade. New users can find it similar to the Programs and Features option within the Control Panel in Windows.

aptitude provides a command-line interface that emulates similar arguments as apt-get or apt utilities. Hence, it is convenient for users who prefer to have a graphical or interactive interface for performing command-line tasks on Linux. aptitude is generally available by default in most Ubuntu or Debian-based distributions. If not, you can install it as follows:

        sudo apt-get update
sudo apt-get install aptitude

Use the following command to search for packages via the aptitude command-line interface:

        sudo aptitude search <package_name>
    

Run the following command in the terminal to launch the aptitude GUI:

        sudo aptitude
    

Press Ctrl + T to move around the terminal. Use arrow keys to navigate through the aptitude GUI. Go to the Search tab and select FIND or press / to launch the browse prompt and type the package name to search.

Aptitude GUI

Searching for Software Packages in Ubuntu

This article covered all the main tools that you can use to search for installed or uninstalled packages on Ubuntu and Debian-based systems. It also shows how to search for the packages using a single keyword or find software/programs that require an upgrade.

As you can see, the main difference between these tools is in their output. Besides, the tools covered are very helpful in finding the packages when you do not exactly know the name or their usage.