Ubuntu

How to Search for Available Packages from the Command Line in Ubuntu?

How to Search for Available Packages from the Command Line in Ubuntu copy

The Ubuntu Operating System consists of a bunch of Packages Installed which can be listed by the User. In some cases, the user requires any additional packages, either as a dependency or to install the whole package on their Ubuntu System. For this reason, the Ubuntu user requires access to the repository to check for the available packages that they can install. The installed packages either crash or return an error where the user can no longer use that package. Thus, the need to see the available packages arises so that the user can Download, Troubleshoot, and keep their Ubuntu System Up-to-date.

This article demonstrates the useful commands to list the available packages on Ubuntu through the Terminal/Command Line.

How to Search for Available Packages from the Command Line in Ubuntu?

The “apt” command, the “apt-cache” command, and the “dpkg” commands are useful built-in Ubuntu Commands that can be used for various purposes including searching for Available Packages. Apart from these three commands, the “aptitude” is also a useful third-party tool used for searching for available packages on your Ubuntu System. To list available packages we will use the approaches mentioned below:

  • Using the “apt search” Method.
  • Using the “apt list” Method.
  • Using the “dpkg” Method.
  • Using the “apt-cache” Method.
  • Using the “aptitude” Method.

List Available Packages Using the “apt-cache” Command

To list the available packages in the Terminal, the “apt-cache” is among the widely used commands. It can be used to list all the available packages that you can install on your Ubuntu System as well and you can use it to search for a specific available package using the name of the package. The “apt-cache” Command has the syntax:

apt-cache search <option>

Both procedures for listing all available packages as well as listing specific packages are discussed below.

List All Available Packages

To list all the available packages on your Ubuntu Terminal, the “apt-cache” command is used along with the search command and the dot(.) option:

apt-cache search .

The dot(.) option will list all the available packages that you can install on your Ubuntu System:

List Available Packages by Name

Instead of listing all the available packages on the Terminal, you can list specific available packages as well. Along with the “search” command, by specifying the Package Name, the Command line will list only the Available Packages of the specified name:

apt-cache search <packageName>

In our case, to search for all the available packages of “PHP”, the “apt-cache” command will be:

apt-cache search PHP

The Terminal will display all the PHP Packages that are available:

List Available Packages Using the “apt search” Command

The simple “apt” command is also a useful way to list the available packages for your Ubuntu System. It searches from the list of available packages and lists the dependency packages as well. The “apt” command is used along with the “search” command and the name of the Package you want to search:

apt search <packageName>

In our case, to list the available “firefox” packages from the available packages, the “apt search” command is:

apt search firefox

The Terminal will display all the available packages of Firefox:

Now, the “apt” command can also be used to list available packages without listing the dependencies packages too. This will list only the packages containing the package name in it. In our case, to list the packages only containing the Firefox package name, the “grep” command is used along with the “apt” command:

apt search firefox | grep firefox

The Terminal will only list the Available Firefox Packages without dependencies:

List Available Packages Using the “apt list” Command

The “apt list” is another useful command to display all the available, upgradeable, and installed packages in the Terminal. To list the available packages using the “list” command, the “apt” command can simply be used as

apt list

The Terminal will display all the available, installed, and upgradeable packages:

You can also list specific installed, available, and upgradeable packages on your Ubuntu System by specifying the Package Name:

apt list <packageName>

In our case, we will list all the available, installed, and upgradeable packages of “python3” using the “apt list” command:

apt list python3

The installed and available packages of “python3” will be listed in the Terminal:

You can also list only the upgradeable packages using the “apt list” command with the “–installed” option:

apt list --upgradeable

Only the upgradeable packages will be listed in the Terminal:

List Available Packages Using the “dpkg” Command

The “dpkg” command lists the available packages in a new window mode inside the Terminal. To list all the available packages with the “dpkg” command, the “-l” option is used:

dpkg -l

The new Terminal Window will display all the installed, available, and upgradeable packages:

You can see more packages by pressing the down “” arrow:

To quit this menu, press “q”.

Search Available Packages with the “dpkg” Command According to a Pattern

You can also use the “dpkg” to Search for packages that end with a specific query using the command:

dpkg -l '*<endingWords>'

In our case, we will list all the packages that end with the word “common” using the “dpkg” command:

dpkg -l '*common'

As you can see in the Terminal, only the packages ending with “common” are listed:

You can also search for packages that start with a specific query using the “dpkg” command:

dpkg -l '<startingWords>*'

In our case, to list only the packages that start with the word “fire”, the “dpkg” command will be:

dpkg -l 'fire*'

As you can see in the Terminal, only the packages starting with the “fire” word are listed:

List Available Packages Using the “aptitude” Command

The Aptitude is also a useful common line utility to list all the packages in the Terminal. It is not pre-installed on your Ubuntu System and can be installed using the “apt install” command:

sudo apt install aptitude

Wait for the Aptitude Packages to be added to your Ubuntu System:

Once added, you can search for packages using the “aptitude” command along with the Package Name:

aptitude search <packageName>

In our case, we will search for the packages of “firefox” using the Aptitude command:

aptitude search firefox

The Terminal will display all the available packages of Firefox:

Conclusion

In some cases, the Installed packages either crash or return an error where you can no longer use that package and require the need to install a new package. Thus, before installing a new package, you have to check all the available packages either using the “apt search” command, the “apt list” command, the “apt-cache” command, the “dpkg” command, or the “aptitude” command. This article explained the use of each command in detail.

Similar Posts