878

I have successfully installed some packages using the command:

sudo apt-get install packagename

when I have known in advance that those packages are available. But how can I search for or get a list of what is available in the repositories?

Mark Thomas
  • 8,895

9 Answers9

1054

To search for a particular package by name or description:

From the command-line, use:

apt-cache search keyword

where the search keyword can be all or part of a package name or any words used in its description.

For example, apt-cache search proxy includes both these packages:

tinyproxy - A lightweight, non-caching, optionally anonymizing HTTP proxy
tircd - ircd proxy to the twitter API

Note: the list may be long, so you can pipe the output to less to make it scrollable one line or one screen at a time, i.e. apt-cache search something | less.

To get a list of ALL packages

apt-cache search .

Use Synaptic if you have X-forwarding enabled or are on a desktop

Synaptic is often a more convenient way to do this, but requires at least an X server on your end (unless you're running a desktop environment). Install with sudo apt-get install synaptic if necessary.

  • Synaptic on ssh'd server via X forwarding:

    enter image description here

  • Synaptic running locally on Ubuntu Desktop:

    enter image description here

ish
  • 139,926
  • @MarkThomas Try apt-cache policy too, it gives you more information about the sources. – yclian Mar 21 '15 at 02:44
  • 1
    like apt-get, you can just run apt-cache without any arguments and get the short help/cheatsheet info. You can always read the manpages on it for longer help. (i.e. man apt-cache ) – pd12 Oct 28 '15 at 01:08
  • Supposing that I'm foolish enough to want to live the results into apt install, is there a smart way to do that? The output from this function is messy. One could use the first word from each line, but there should be an easier way. – CoderGuy123 Nov 04 '16 at 07:41
  • you can also search online. https://packages.ubuntu.com/ – activedecay Sep 08 '17 at 05:18
  • If you only need the names of all the packages available just do apt-cache pkgnames – flaz14 Feb 15 '18 at 11:15
  • Doesnt this only return cached stuff?? – Black Sep 24 '20 at 15:31
92

Using aptitude, apt-cache, and apt all format the output differently. (None of these require the use of sudo when searching for a package.) I prefer using apt for its readability. It highlights the package name and puts a space between the different packages. It also has [installed] listed next to each package that is already installed. Usage:

apt search keyword
jbrock
  • 3,307
  • 7
    if i run say '$ apt search firefox' it produces tons of output results :( – user3804598 Jan 02 '18 at 17:45
  • 1
    You could narrow your search with something like: apt search firefox | grep -A 3 firefox – jbrock Apr 16 '18 at 16:01
  • 4
    Another option to narrow the search: apt search ^firefox or apt search ^firefox$ – jbrock Jul 26 '19 at 08:24
  • 3
    @jbrock if your output is not a tty but a pipe like in apt search firefox | grep -A 3 firefox then you should use apt-cache search instead. The output of the apt tool is meant for human consumption and can change without notice. The apt-get and apt-cache tools have stable output that can be used in scripts and pipelines like yours. – josch May 25 '20 at 10:53
  • @user3804598 true, a better option is apt list firefox – Fadi Feb 05 '22 at 19:50
29

You can also use aptitude from the command line:

aptitude search xxxxxx
lxx
  • 391
  • 2
    The annoying thing about this one is that Ubuntu doesn't seem to give it to you by default. Up until I learnt about apt-cache, I was always having do so apt-get install aptitude on each new box I installed. However, since I can't find a way to get apt-cache to show me whether it's installed, I guess I'll have to keep doing that for a bit :-) –  May 05 '16 at 06:39
  • 2
    @paxdiablo Just create two line shell script (second line someting like dpkg --list | grep "$1") or add shell function to this effect into your .bash_login... :-) – FooF Aug 12 '16 at 03:43
10

The apt-cache command line tool is used for searching apt's software package cache. In simple words, this tool is used to search software packages, collect information about packages and also search for what packages are available and ready for installation on Debian- or Ubuntu-based systems.

To find a package's name along with its description before installing, use the search flag. Using search with apt-cache will display a list of matched packages with a short description.

The general syntax of apt-cache search is:

apt-cache search SearchTerm

where SearchTerm is the term you wish to search for. For example, let’s say you would like to find the description of the vsftpd package. The command you would use would be:

apt-cache search vsftpd

The possible output would be:

vsftpd - lightweight, efficient FTP server written for security
ccze - A robust, modular log coloriser
ftpd - File Transfer Protocol (FTP) server
yasat - simple stupid audit tool

To find and list down all the packages starting with vsftpd, you could use the following command.

apt-cache pkgnames vsftpd

You may also want to run the results through more or even grep commands. For instance:

apt-cache search firefox | grep plugin
U.Swap
  • 201
7

Unfortunately I don't have enough rep to add this a comment on the main answer.

But I was trying to find g++- - alike packages with apt-cache search. It's important to know in this case that keyword is a regular expression so apt-cache search g++- will not have helpful results.

apt-cache search "g[+][+][-]" would be the way to go

7

Assuming you want to do all of this from the terminal use the following:

first I recommend you update the package index files so the list of all files in the repository you are about to create is up to date

sudo apt-get update

then use "search regex" function in apt-cache where "regex" stands for Regular Expression and is the pattern given to search. For more info about search patterns you can look up manual regex(7) by command man 7 regex or in English. A regex variable equal to . will suffice.

apt-cache search .

The above will give you ALL the results but it is not in any order that is particularly helpful for browsing.

So finally we can sort by dictionary order usingsort -d and show only a page at a time usingless.

apt-cache search . |sort -d |less
6

apt list <package> is how I recommend searching for packages. If you don't get any matches or if you're not sure what the package is named, try wrapping the argument in asterisks to get more results. For instance apt list *chrome* will yield the following:

Listing...
chrome-gnome-shell/focal,focal,now 10.1-5 all
chromium-chromedriver/focal-updates 1:85.0.4183.83-0ubuntu0.20.04.2 amd64
chromium-lwn4chrome/focal,focal 1.0-3 all
google-chrome-beta/stable 99.0.4844.17-1 amd64
google-chrome-stable/stable,now 98.0.4758.80-1 amd64
google-chrome-unstable/stable 100.0.4867.0-1 amd64
mkchromecast-alsa/focal,focal 0.3.8.1-1 all
mkchromecast-gstreamer/focal,focal 0.3.8.1-1 all
mkchromecast-pulseaudio/focal,focal 0.3.8.1-1 all
mkchromecast/focal,focal 0.3.8.1-1 all
node-chrome-trace-event/focal,focal 1.0.2-1 all
openchrome-tool/focal 1:0.6.0-3build1 amd64
python3-pychromecast/focal,focal 4.1.0-1 all
ruby-chromedriver-helper/focal,focal 2.1.0-7 all
xserver-xorg-video-openchrome-hwe-18.04/focal 3:14.5 amd64
xserver-xorg-video-openchrome/focal 1:0.6.0-3build1 amd64

Alternatively, if you'd like a description of each package, run apt search --names-only <package>. Make sure to include --names-only for more accurate results.

Fadi
  • 695
  • 1
  • 8
  • 17
1

The OP aimed only to apt, which was already answered (apt search). Some people might end up here searching for solutions for other (more modern) alternatives.

Nowadays we have other sources for apps: pip, brew, flatpak and npm, to name a few popular ones. All of them also works with search subcommand.

You could handle all of the above and others with meta-package-manager, which solves XKCD #1654 (don't look #927).

Pablo Bianchi
  • 15,657
0
apt-file search part_of_package_name

"Extended variant" is useful in case of excessive number of results:

apt-file search part_of_package_name | grep another_part_of_name

Example of searching for ssh server package if I do not know the name is ssh-server or sshserver or server-ssh etc.:

apt-file search ssh | grep server

Steps to prepare apt-file search for searching. It should be done before first usage:

sudo apt-get install apt-file
sudo apt-file update
netbat
  • 1,044
  • 3
  • 12