How To Search Available Packages From Command Line In Debian, Ubuntu Or Linux Mint [APT]

There are multiple ways of searching for packages available in the Debian, Ubuntu or Linux Mint from the command line, and in this article I'll cover apt, apt-cache and aptitude. Use this to search in both package names and package descriptions, useful if either you're looking for a specific package but you don't know the exact package name, or if you need a tool for a particular purpose / task but you don't know the available options.

The major differences between using apt, apt-cache and aptitude to search for available packages is their output and the sort order, as you'll see in the examples below. Also, aptitude may not be installed by default on your Debian-based Linux distribution.

I personally prefer apt-cache because of the easier to read output (and I don't need extra info usually - to see installed/available versions I can use apt-cache policy package-name); it also tends to display the results I'm looking for near the top.

Another thing to note is that apt and apt-cache search the apt software package cache, so they return both packages available in the repositories as well as DEB packages installed manually (not available in the repos), while aptitude only returns packages that are available in the repositories.

I. Search available packages using aptitude

aptitude is a Ncurses-based front-end for apt. This tool is usually not installed by default but you can install it in Debian, Ubuntu, Linux Mint and other Debian-based Linux distributions using this command:

sudo apt install aptitude

You can use aptitude to search for packages from the command line, like this:

aptitude search KEYWORD

Example:

$ aptitude search openssh

p   libconfig-model-openssh-perl                           - configuration editor for OpenSsh                                
p   libghc-crypto-pubkey-openssh-dev                       - OpenSSH key codec  
p   libghc-crypto-pubkey-openssh-dev:i386                  - OpenSSH key codec  
v   libghc-crypto-pubkey-openssh-dev-0.2.7-6af0a           -                    
v   libghc-crypto-pubkey-openssh-dev-0.2.7-6af0a:i386      -                    
p   libghc-crypto-pubkey-openssh-doc                       - OpenSSH key codec; documentation                                
p   libghc-crypto-pubkey-openssh-prof                      - OpenSSH key codec; profiling libraries                          
p   libghc-crypto-pubkey-openssh-prof:i386                 - OpenSSH key codec; profiling libraries                          
v   libghc-crypto-pubkey-openssh-prof-0.2.7-6af0a          -                    
v   libghc-crypto-pubkey-openssh-prof-0.2.7-6af0a:i386     -                    
p   libnet-openssh-compat-perl                             - collection of compatibility modules for Net::OpenSSH            
p   libnet-openssh-parallel-perl                           - run SSH jobs in parallel                                        
p   libnet-openssh-perl                                    - Perl SSH client package implemented on top of OpenSSH           
p   lxqt-openssh-askpass                                   - OpenSSH user/password GUI dialog for LXQt                       
p   lxqt-openssh-askpass:i386                              - OpenSSH user/password GUI dialog for LXQt                       
p   lxqt-openssh-askpass-l10n                              - Language package for lxqt-openssh-askpass                       
v   lxqt-openssh-askpass-l10n:i386                         -                    
i   openssh-client                                         - secure shell (SSH) client, for secure access to remote machines 
p   openssh-client:i386                                    - secure shell (SSH) client, for secure access to remote machines 
p   openssh-client-ssh1                                    - secure shell (SSH) client for legacy SSH1 protocol              
p   openssh-client-ssh1:i386                               - secure shell (SSH) client for legacy SSH1 protocol              
p   openssh-known-hosts                                    - download, filter and merge known_hosts for OpenSSH
p   openssh-server                                         - secure shell (SSH) server, for secure access from remote machines
p   openssh-server:i386                                    - secure shell (SSH) server, for secure access from remote machines 
p   openssh-sftp-server                                    - secure shell (SSH) sftp server module, for SFTP access from remote machines
p   openssh-sftp-server:i386                               - secure shell (SSH) sftp server module, for SFTP access from remote machines

You can also use the aptitude Ncurses UI if you wish. Type aptitude to start it:

Aptitude ncurses interface

You can search packages by pressing / and then start typing the keyword.

II. Search available packages using apt-cache

Use apt-cache to to search for packages available in the Debian, Ubuntu or Linux Mint repositories (and installed DEB packages that aren't in the repositories) like this:

apt-cache search KEYWORD

Example:

$ apt-cache search openssh

openssh-client - secure shell (SSH) client, for secure access to remote machines
openssh-server - secure shell (SSH) server, for secure access from remote machines
openssh-sftp-server - secure shell (SSH) sftp server module, for SFTP access from remote machines
python-setproctitle - Setproctitle implementation for Python 2
python3-setproctitle - Setproctitle implementation for Python 3
ssh - secure shell client and server (metapackage)
agent-transfer - copy a secret key from GnuPG's gpg-agent to OpenSSH's ssh-agent

...

ssh-askpass-gnome - interactive X program to prompt users for a passphrase for ssh-add
ssh-audit - tool for ssh server auditing
sshpass - Non-interactive ssh password authentication

I removed some of the output because it can get very long. The visible results order was not changed though.

III. Search available packages using apt

Using apt you can search for available packages from the command line as follows:

apt search KEYWORD

Replace KEYWORD with the keyword you want to search for (you can add multiple keywords in quotes).

Here is an example search for "openssh" together with its output:

$ apt search openssh

Sorting... Done
Full Text Search... Done
agent-transfer/bionic 0.41-1ubuntu1 amd64
  copy a secret key from GnuPG's gpg-agent to OpenSSH's ssh-agent

cme/bionic,bionic 1.026-1 all
  Check or edit configuration data with Config::Model

connect-proxy/bionic 1.105-1 amd64
  Establish TCP connection using SOCKS4/5 or HTTP tunnel

...

openssh-client/bionic,now 1:7.6p1-4 amd64 [installed]
  secure shell (SSH) client, for secure access to remote machines

openssh-client-ssh1/bionic 1:7.5p1-10 amd64
  secure shell (SSH) client for legacy SSH1 protocol

openssh-known-hosts/bionic,bionic 0.6.2-1 all
  download, filter and merge known_hosts for OpenSSH

openssh-server/bionic 1:7.6p1-4 amd64
  secure shell (SSH) server, for secure access from remote machines

openssh-sftp-server/bionic 1:7.6p1-4 amd64
  secure shell (SSH) sftp server module, for SFTP access from remote machines

putty-tools/bionic 0.70-4 amd64
  command-line tools for SSH, SCP, and SFTP

python-scp/bionic,bionic 0.10.2-1 all
  scp module for paramiko

Once again, I removed some of the results because the results list is quite long. The results order was not changed though.


For all three, the search results may be very long. In such cases, you can run them through more, for easier reading, like this:

apt-cache search KEYWORD | more

You can also exclude results that don't include a particular keyword (KEYWORD2 in this example) by using grep:

apt-cache search KEYWORD | grep KEYWORD2

grep is case sensitive by default. Add -i (grep -i KEYWORD2) to ignore case.

No comments:

Powered by Blogger.