Why, and how to debug: The following packages have unmet dependencies, ... but it is not going to be installed

$ sudo apt install cuda
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cuda : Depends: cuda-11-4 (>= 11.4.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

What does "it is not going to be installed" mean? Why? Why is it not installing the dependencies? How can I find out?

What does "you have held broken packages" mean? Which broken packages? How can I find out?

What does "impossible situation" mean? How can I get some more details about it?

Related is this earlier similar message, which is also still unanswered. But here, it also prints "you have held broken packages", and this "impossible situation", so maybe it is slightly different.

I'm not specifically asking about this specific cuda package here. I'm also not asking about how to solve or fix anything here. I'm asking just about how to debug and understand and handle such apt (or apt-get) messages in general, for any package.


Solution 1:

I fully agree that many apt messages are a lot more cryptic that one would like and often they are even misleading. The good thing is, however, that when working with apt for a while you will come across the messages over and over again and get used to how to fix them.

Depending what you know about what apt does behind the scenes it might not be so easy to understand all details. I'll give it a trial hoping to guess you background and interpreting your question correctly. Please bear with me if I got it wrong :-)

In general the messages you refer to "will not be installed" or "impossible to" refer to the dependencies that are required for your package you are installing versus he packets already installed on your system.

To understand this you need to know that most packages do not ship with all the files they actually need to run. Linux custom is to use open source software whereever you can, so each package uses a lot of libraries. That are binary blobs filled with functions that an executable can use on the fly. Trouble is that on the one hand those open source project change all the time and get very frequent updates and on the other hand the programs are coded to work with a specific version, i.e. the version the developer had been using at the time of compiling. So you need exactly that version or a compatible version. It would be easy if every developer, e.g. of CUDA would ship all the libraries they used during compilation. They don't because most are standard libraries that verly likely are used by other programs as well and it would mean that each program would be huge to download and to store all this duplicate data (Docker or AppImage by the way are exactly doing that to provide a solution to this problem). Due to this issue you typically have multiple versions of system libraries on your system. It gets tricky, however, when libraries are incompatible or conflicting with each other, e.g. because only one lib can access a system resource at a time. In that case you must find the library version that is compatible to all installed packets that is using them.

Thats what apt is trying to do for every installation you do. Its not an AI so there are limits to what it can do. The message impossible situation is that you clearly have a conflict where two absolutly incompatible versions of a library are needed at the same time. More often than not theses are not the direcly used libraries, but libraries the libraries need to run. There is a whole hierarchy of dependencies. Its very instructive to got to github for any decent bit of software and follow the compilations instructions. Compilation in Linux is really easy. But most of the time its a nightmare to get all depencenies located and installed. And if you are not using the newest but older versions, you can not use the newest dependencies but you need also to find out which source code versions you need for each of the dependencies. Doing that gives a very good feel what apt is working with. The message "it's not going to be installed" thus could be caused that a required library is available and would work fine, but any of their dependency has a conflict somewhere down the line.

Now, what can you do? You can solve it better than apt when you trace every conflict and then find out which other application is affected and then decide which if important and which not. For example you could find out that your blocker for the CUDA install is a default messenger tool you are not using anyway. The easy solution is to uninstall this one and all its libs (when they are not used anywhere else apt will do that). After that apt can install it. Unfortunately I am not aware of any tool that allows you to browse those dependency trees in a way to easily understand and trace those connections.

I have these cases as well and the first thing is to try Aptitude. Its not installed by default:

  sudo install aptitude

Aptitude is basically the same than apt, but its larger and has a lot more logic to handle these cases. In case of those messages aptitude will offer you options. Some might be bogus, just say "no" and you get another one. It will for example suggest to "downgrade" a package. That means install an older version. It will suggest to "delete" a package, or install additional packages as workaround. Touble is it does not tell you what the consequences are, i.e. it does not tell you "if you downgrade this, the application XYZ might not work properly any more". It just gives you options out of the dilemma that "apt" was not able to solve.

So looking at the suggestions from Aptitude, its a good idea to see which packages pop up and if you can make connections yourself. You might note that there is a tool involved you recently installed. It might give you a hint to anything you do not use anyway. Uninstall it and try again. Also fire up a VM with a blank Ubuntu and try to install your stuff there can be very useful, because you see if the Ubuntu release has the conflict out of the box. They its time to get to places like this and make a post as specific as possible.

Hopefully I did neither lost you nor bored you and it targets your question a bit.

Now apt is behind the scenes quite complex, because its written in a low level language and thus its quite difficult to include complex or advances detection and resolving algorithms. Its made to be a robust and small footprint tool running on every (even minimal) system. And that it is.