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?

karel
  • 114,770

4 Answers4

60

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.

Daryn
  • 105
  • 3
  • 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. –  Feb 01 '17 at 02: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. – David Foerster Feb 01 '17 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 '17 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 03 '18 at 09:45
  • 1
    For later arrivals, the comments above discuss an older version of this answer. Current answer just sudo apt-get update is free of controversy and was the correct solution for me. – Daryn Oct 31 '19 at 10:14
  • 1
    Solved it for me. Thanks! – ubuntuuber Jul 26 '20 at 22:02
  • 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 04 '20 at 05:52
  • 1
    In my case, I ran into this issue in an interactive shell of a docker container. It was built running rm -rf /var/lib/apt/lists/* after installing packages. The above solution worked for me. – Stefan Rickli Mar 12 '21 at 20:06
  • I don't think this answer the main question, "Is there a command or option I can use to determine what package / which packages reference the missing package?" – PhoneixS May 25 '22 at 12:55
  • This answer helped me fix this error for the lsb-core package on Ubuntu, but not on Debian. But then I found out that apparently Debian discontinued LSB support in 2015 (LSB = Linux Standard Base). By running apt list lsb*, I found out that lsb-base and lsb-release are the only two supported LSB packages. So all I needed to do to install the lsb_release command was to run: sudo apt install -y lsb-release. – Henke - Нава́льный П с м Nov 21 '22 at 17:11
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.

  • 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 07 '19 at 02:37
  • @Erhannis Does 'terminfo' bring anything up? I think sometimes this error comes up when a package is sloppily renamed. – Arlo James Barnes Nov 16 '19 at 08: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 '19 at 01:45
  • 1
    doesn't work for php7.4-fpm – Sumit Wadhwa Jun 14 '21 at 09: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 '22 at 07: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
Flimm
  • 41,766
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.

xquilt
  • 117