13

I understand that this sounds like a ridiculous question but here is what I am trying to do: Install the apache http server.

So I run apt search apache and get a ton of results.

Actually... apt search apache | wc -l and dividing by 3 - I seem to get about 700 results.

  1. I can try to narrow this down using apt search apache http and then I get about 200 results and then I can scroll a lot and it will eventually turn up.

  2. I can also use apt search --names-only apache and at least exclude all those things that only mention apache in the description. That brings it down to 110 results.

All of this seems pretty complicated and tedious given that the package that I am looking for is called "apache2". Is there some way to get a best fit sorting of results? Or some other tool I should use?

FranzReprimand
  • 233
  • 1
  • 2
  • 5

6 Answers6

10

You seem to know how the package should be called, or at least what a part of its name should be. apt search doesn’t look like the best tool for this task, use apt list instead:

$ apt list apache\*
Listing... Done
apache2/bionic-updates,bionic-security 2.4.29-1ubuntu4.11 amd64
apache2-bin/bionic-updates,bionic-security 2.4.29-1ubuntu4.11 amd64
apache2-data/bionic-updates,bionic-updates,bionic-security,bionic-security 2.4.29-1ubuntu4.11 all
apache2-dbg/bionic-updates,bionic-security 2.4.29-1ubuntu4.11 amd64
apache2-dev/bionic-updates,bionic-security 2.4.29-1ubuntu4.11 amd64
apache2-doc/bionic-updates,bionic-updates,bionic-security,bionic-security 2.4.29-1ubuntu4.11 all
apache2-ssl-dev/bionic-updates,bionic-security 2.4.29-1ubuntu4.11 amd64
apache2-suexec-custom/bionic-updates,bionic-security 2.4.29-1ubuntu4.11 amd64
apache2-suexec-pristine/bionic-updates,bionic-security 2.4.29-1ubuntu4.11 amd64
apache2-utils/bionic-updates,bionic-security 2.4.29-1ubuntu4.11 amd64
apachedex/bionic,bionic 1.6.2-1 all
apacheds/bionic-updates,bionic-updates,bionic-security,bionic-security 2.0.0~M24-2~18.04 all
apachetop/bionic 0.12.6-18build2 amd64

From apt manual:

list is somewhat similar to dpkg-query --list in that it can display a list of packages satisfying certain criteria. It supports glob(7) patterns for matching package names as well as options to list installed (--installed), upgradeable (--upgradeable) or all available (--all-versions) versions.

The escaped asterisk (\*) means that any character(s) may follow the name. If you find nothing, consider adding the escaped asterisk to the beginning of the search string.

I am pretty sure you can choose the right one from this list. Obviously, the first is the actual Apache server. Selecting the apache2 package will also install its dependencies automatically.

$ sudo apt install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0
  ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom openssl-blacklist
Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Melebius
  • 11,121
  • 8
  • 50
  • 77
7

You could use the grep command :

apt-cache search apache2 | grep apache2

and if you don't like the red color of grep, just add the --color=none option :

apt-cache search apache2 | grep apache2 --color=none

P.S : I recommend you to not forget the -cache option, you won't see the package name if you don't add it by using grep command (see below the result without this option) :

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

  Apache HTTP Server (mod_ssl development headers)
  WebSocket extension for Apache HTTP Server

EDIT : Thanks to @pymym23, you would sort better your results by using the description, for example

apt-cache search apache2 | grep "Apache HTTP Server"

Result :

apache2-ssl-dev - Apache HTTP Server (mod_ssl development headers)
python-mod-pywebsocket - WebSocket extension for Apache HTTP Server

Also, you must use the -i option, it won't sort result if you don't type a capital letter instead of a little one

Example :

apt-cache search apache2 | grep "apache HTTP Server"

and you got no result

apt-cache search apache2 | grep -i "apache HTTP Server"

and result is :

apache2-ssl-dev - Apache HTTP Server (mod_ssl development headers)
python-mod-pywebsocket - WebSocket extension for Apache HTTP Server
damadam
  • 2,815
  • 3
  • 17
  • 38
  • 6
    If you know it is apache2 there is no need to search for it. HOW to use apt search to find out it was apache2 he is looking for is the question ;-) – Rinzwind Oct 16 '19 at 09:35
  • Maybe `apt-cache search Apache HTTP Server | grep "Apache HTTP Server"` will fit better ? Or does it only concern `apt search` ? – pymym213 Oct 16 '19 at 09:37
  • @pymym213 this is a good idea, and there is only 2 results with `apt-cache search apache | grep "Apache HTTP Server"` – damadam Oct 16 '19 at 09:39
  • @pymym213 Interesting that there is a difference in output. Always thought apt-cache search and apt search did the same thing. – FranzReprimand Oct 16 '19 at 10:11
  • @FranzReprimand i add for you the result without `-cache` option (that's also my 1rst time that I see difference between these 2 x) – damadam Oct 16 '19 at 10:16
  • For those just bopping into this from another OS, the use of the term "option" here in comments and answer is incorrect. -cache isn't an option, it's the last part of the name `apt-cache`. `apt` is a wrapper for the collection of `apt-*` utilities out there. – tgm1024--Monica was mistreated Mar 05 '20 at 19:50
3

I find a good way of searching for this is tab complete

sudo apt install apache<tab><tab>

gives

 sudo apt install apache
apache2                  apache2-doc              apachedex
apache2-bin              apache2-ssl-dev          apacheds
apache2-data             apache2-suexec-custom    apachetop
apache2-dbg              apache2-suexec-pristine  
apache2-dev              apache2-utils  

if that fails just type in the command

~$ apache

Command 'apache' not found, did you mean:

  command 'apache2' from deb apache2-bin

Try: sudo apt install <deb name>

Modern distros are pretty good at knowing what you meant

If that fails I usually fall back to apt search / apt list or more frequently these days search docker hub and install though docker

exussum
  • 445
  • 3
  • 13
0
apt search **package-name**

example: let say you searching for mysql-server ->

apt search mysql-server

Output:

    sk@sk-desktop:~$ apt search mysql-server
Sorting... Done
Full Text Search... Done
default-mysql-server/bionic,bionic 1.0.4 all
  MySQL database server binaries and system database setup (metapackage)

default-mysql-server-core/bionic,bionic 1.0.4 all
  MySQL database server binaries (metapackage)

mysql-server/bionic-updates,bionic-updates,bionic-security,bionic-security,now 5.7.27-0ubuntu0.18.04.1 all [installed]
  MySQL database server (metapackage depending on the latest version)

mysql-server-5.7/bionic-updates,bionic-security,now 5.7.27-0ubuntu0.18.04.1 amd64 [installed,automatic]
  MySQL database server binaries and system database setup

mysql-server-core-5.7/bionic-updates,bionic-security,now 5.7.27-0ubuntu0.18.04.1 amd64 [installed,automatic]
  MySQL database server binaries
0

I am agree with the solution about apt list is better about results presentation than apt search, but more info is available through

  • apt list | grep <package_name>

and with the --installed parameter such as:

  • apt list --installed | grep <package_name>

shows what is installed for that package.

Therefore without the parameter it returns what and where is available about the package, so, you know what you would want to install, and with the parameter, you can confirm if you have already installed the package

Manuel Jordan
  • 1,355
  • 4
  • 22
  • 39
0

I'm looking for compatible packages to come from CentOS to Ubuntu Server. This was okay-ish:

apt search apache2 | more

So I tried this based off of @exussum's answer and it worked great.

apt list apache2<tab><tab>