66

It is not unusual for a user of Ubuntu (or other distro using the apt package management tool to encounter the error:

user@box ~ $ sudo apt install x
[sudo] password for user: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package x is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'x' has no installation candidate

There have been several questions asked concerning this on various Stack Exchange sites, for example Package network-manager-openvpn is not available on Ask Ubuntu, but these are generally about how to obtain the specific package despite the error.

I have found no package that is not found simply (though not always easily) by determining if it is still distributed, and under which repository, and ensuring the repository is in sources.list, or if the worst comes to worst, downloading a .deb file or a source file to compile.

So my question is more general, and although I am guessing it has a rather simple and therefore non-exciting answer I cannot think how to find it by conventional search engine methods, so I turn to Ask Ubuntu.

Is there a command or option I can use to determine what package(s) reference the missing package?

4 Answers 4

59

Sometimes this happens because APT just doesn't know anything about what you're talking about, but that can be solved by running:

sudo apt-get update

After running this, typically the error goes away because apt and apt-get know how to do what I ask now.

10
  • 7
    You probably meant apt-get update followed by apt-get upgrade -y because -y bypasses user confirmation. It makes no sense using it with apt-get update. Even so, this doesn't answer the question, at all.
    – user589808
    Feb 1, 2017 at 2:46
  • 4
    @CelticWarrior: I agree with this answer in principle because updating the package repository information can resolve this issue if one tries to install a package from a recently added PPA and forgot to run apt-get update. Feb 1, 2017 at 11:59
  • 12
    @user589808 I don't think that is very good advice at all. An apt-get upgrade is not necessary, and blindly hitting -y to everything can break more things than it fixes. so wayne was correct in hi syntax.
    – crazy cool
    Jul 18, 2017 at 20:09
  • 1
    apt-get update answers the A-B question (the package exists in the repo but apt-get install and apt-cache don't know about it.)
    – dcorking
    May 3, 2018 at 9:45
  • 3
    Solved? Not for me. Doesn't matter using update, upgrade, cache, etc... the message rest the same: Package php-pear is not available, but is referred to by another package. It's a docker installation on wsl2 environment.
    – mirapole
    Aug 4, 2020 at 5:52
19

You can search for the package with apt-cache:

apt-cache search x

This will output all packages that in a way or another make a reference to x.

5
  • 16
    Well, that sounds reasonable...except it isn't working for me. apt-get install libtinfo6 reports unavailable but referred to by another package, but apt-cache search libtinfo6 yields no results. Is there some other way of doing a similar thing?
    – Erhannis
    Nov 7, 2019 at 2:37
  • @Erhannis Does 'terminfo' bring anything up? I think sometimes this error comes up when a package is sloppily renamed. Nov 16, 2019 at 8:19
  • 1
    I'm...not sure. I upgraded to the next version of Debian, and that package apparently no longer gives that error. I'll try terminfo the next time it happens, though; it's happened before and it will likely happen again.
    – Erhannis
    Nov 20, 2019 at 1:45
  • 1
    doesn't work for php7.4-fpm Jun 14, 2021 at 9:12
  • apt-cache search searches the package names and descriptions of packages. It does not search the list of dependencies of each package.
    – Flimm
    May 10, 2022 at 7:54
3

You can run this command to see all the reverse dependencies of a package (replacing PACKAGENAME with the package name):

apt-cache showpkg PACKAGENAME

What's a reverse dependency? If package X depends on package Y, then Y is a dependency of X, and X is a reverse dependency of Y.

Try removing some of the reverse dependencies by running sudo apt remove NAME.

You may also want to try removing all the configuration for the package that may not be available any more:

sudo apt purge PACKAGENAME
1
  • 1
    This is the very correct answer when apt-cache search gives nothing.
    – user109764
    Aug 26, 2022 at 20:02
0

Based on previous encounters, oftentimes:

  • Substring package searching using apt search, can sometimes be a viable option, but It's also possible that the package name is unrelated, counter-intuitive, or entails intermediary characters, that gets the search process to no avail. At such case, you can google the respective name at the official repositories of the desired package or library, which usually can be conveniently referenced at the package readme or manual.
  • It's also possible that you're trying to install a command (whether it's a binary or executable file) or a module that's encompassed within another metapackage or a library, at which case apt-file search can come in handy.

However, If the package is generally unavailable in any form at the official repositories, then, as a last resort, you can alternatively look for a community-driven repository i.e. PPA that provides the software, manually installing the deb (crossing your fingers in hope for available, installable and compatible dependencies) or compile it yourself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .