12

I am learning how to use apt. When I do an apt-cache search git to see all packages matching git, I see a bunch of packages whose descriptions have nothing to do with git. Why is this so and how can I fix it? (Ubuntu 12.04.2 LTS).

Also, why is the search functionality found in a command that has "cache" in its name? What does search functionality have to do with caches?

Thanks.

15

If you want only to search by name, use the --names-only argument. For more information, read the man apt-cache, it would be useful.

| improve this answer | |
6

When you perform an apt-cache search <package name> command, you are performing a query against the information stored on your local machine for available packages. This is the cache from your "subscribed" repositories. That is, the command is performing a query against the repositories that you have set up in USC(Ubuntu Software Center) or Synaptic.

According to the apt-cache man page, /etc/apt/sources.list is the location to fetch information from in the query. There are a couple of additional locations for other types of package information. See man apt-cache for more details.

Essentially, running apt-cache search git will return all instances of available packages containing the word sequence "git" in the package name, as well as in the package description.

For example, this means that any package that may contain the word sequence "git" in it, like the word "digital", in its description will also be returned as a result. Please note the bold in the previous sentence.

If you are only interested in packages that are specifically concerned with git - the source control manager, you will need to restrict your query to using a regular expression in order to make the search results more restrictive.

For example:

sudo apt-cache search ^git$

will return results that explicitly contain only the phrase "git" in the package name.

For example:

sudo apt-cache search ^git$
git - fast, scalable, distributed revision control system

The command: sudo apt-cache search ^git

will return results for packages which begin with the phrase "git":

For example:

sudo apt-cache search ^git
git - fast, scalable, distributed revision control system
git-core - fast, scalable, distributed revision control system (obsolete)
git-doc - fast, scalable, distributed revision control system (documentation)
git-man - fast, scalable, distributed revision control system (manual pages)
gitk - fast, scalable, distributed revision control system (revision tree visualizer)
easygit - git for mere mortals
gforge-plugin-scmgit - Git plugin for FusionForge (transitional package)
git-all - fast, scalable, distributed revision control system (all subpackages)
git-annex - manage files with git, without checking their contents into git
git-arch - fast, scalable, distributed revision control system (arch interoperability)
...

That said, you will need to tune your queries of the package cache to be more specific to your interest. Hope this helps.

| improve this answer | |
  • "apt-cache search ^git$ will only return results that contain "git" in the package name". I don't understand this, because, for example git-man (from the second output you posted) also contains git. Can you explain what do the caret and the $ symbols mean? I know that the caret means "begins with", but then this contradicts with the second output you posted (output of ^git), because it's returning easygit =). – Alaa Ali Aug 14 '13 at 11:47
  • Oooh. The ^ means packages and descriptions that start with git. Okay, the second output is understood. So what does ^git$ return? Packages that start with git and ...? – Alaa Ali Aug 14 '13 at 11:56
  • @Alaa Think of the characters "^" and "$" as anchors to your query. apt-cache search ^git$ will return, specifically, the git package. apt-cache search ^git will return packages that begin with the phrase "git" and will be less specific. – Kevin Bowen Aug 14 '13 at 12:24
  • One could get a more generalized search result by running the query apt-cache search ^git?` – Kevin Bowen Aug 14 '13 at 12:34
  • In order to have a more colorful output, one could enhance your command with apt-cache search ^git | grep --color git – georg Nov 4 '15 at 8:27
0

This is an indirect answer to your question but still related to it since it's about package management. I personally use aptitude instead of apt-get. aptitude is the synaptic equivalent to terminal.

To search,

sudo aptitude search $keyword

Other commands

sudo aptitude install
sudo aptitude update
sudo aptitude upgrade

To install aptitude,

sudo apt-get install aptitude
| improve this answer | |
  • Keep in mind that aptitude may still be problematic on multiarch systems - so it's ok to use it for queries/searches but not so for installing/removing packages. – guntbert May 22 '13 at 11:08
  • help.ubuntu.com/community/MultiArch explains how aptitude can be used for multiarch concerns – llt May 22 '13 at 11:52
  • That page only mentions aptitude why - like I said "use it for queries" - the page is rather old too (edited 2012-02-08) - so my warning still stands. – guntbert May 22 '13 at 15:45
  • I see. I'm an aptitude user so can you point me to an article where it says its a problematic on multiarch system? I may need to switch back to apt-get then. – llt May 23 '13 at 4:50
  • bugs.launchpad.net/ubuntu/+source/aptitude/+bug/831768, it seems to have been fixed recently. I am still wary. Debian recommends apt-get too (docs for wheezy) – guntbert May 23 '13 at 13:36
0

Install apt-xapian-index and use axi-cache search when searching instead of apt--cache. You'll get much better results

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.