51

all. I'm trying to fix my system so I can install the nvidia drivers but it seems to get stuck for some reason. I have tried manually removing the downloaded files from

/var/cache/apt/archives/libnvidia-gl-390_390.48-0ubuntu3_i386.deb
/var/cache/apt/archives/libnvidia-gl-390_390.48-0ubuntu3_amd64.deb

... in order to let them download again but to no avail. Have anyone tried installing those drivers on 18.04 lately?

~$ sudo apt --fix-broken install
[sudo] password for jarl: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  lib32gcc1 libc6-i386
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libnvidia-gl-390 libnvidia-gl-390:i386
The following NEW packages will be installed
  libnvidia-gl-390 libnvidia-gl-390:i386
0 to upgrade, 2 to newly install, 0 to remove and 4 not to upgrade.
3 not fully installed or removed.
Need to get 0 B/29,1 MB of archives.
After this operation, 147 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 214344 files and directories currently installed.)
Preparing to unpack .../libnvidia-gl-390_390.48-0ubuntu3_i386.deb ...
diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340
dpkg-divert: error: mismatch on package
  when removing 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 by libnvidia-gl-390'
  found 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340'
dpkg: error processing archive /var/cache/apt/archives/libnvidia-gl-390_390.48-0ubuntu3_i386.deb (--unpack):
 new libnvidia-gl-390:i386 package pre-installation script subprocess returned error exit status 2
Preparing to unpack .../libnvidia-gl-390_390.48-0ubuntu3_amd64.deb ...
diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 to /usr/lib/x86_64-linux-gnu/libGL.so.1.distrib by nvidia-340
dpkg-divert: error: mismatch on package
  when removing 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 by libnvidia-gl-390'
  found 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 to /usr/lib/x86_64-linux-gnu/libGL.so.1.distrib by nvidia-340'
dpkg: error processing archive /var/cache/apt/archives/libnvidia-gl-390_390.48-0ubuntu3_amd64.deb (--unpack):
 new libnvidia-gl-390:amd64 package pre-installation script subprocess returned error exit status 2
Errors were encountered while processing:
 /var/cache/apt/archives/libnvidia-gl-390_390.48-0ubuntu3_i386.deb
 /var/cache/apt/archives/libnvidia-gl-390_390.48-0ubuntu3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
2
  • Try to clean the whole cache with sudo apt-get clean and try again. May 12, 2018 at 21:02
  • after sudo apt-get clean same thing still happens for me Aug 28, 2019 at 12:34

6 Answers 6

117

Found this command on ubuntu forums, worked very well with me:

Run:

LC_MESSAGES=C dpkg-divert --list '*nvidia-340*' | sed -nre 's/^diversion of (.*) to .*/\1/p' | xargs -rd'\n' -n1 -- sudo dpkg-divert --remove
sudo apt --fix-broken install

The first command will remove all the diverted packages from nvidia-340. If you have other nvidia version "diverting" change it; read the error code to know which version is diverting.

Source: https://ubuntuforums.org/showthread.php?t=2388026&p=13761809#post13761809 kudos to stutteringp0et2 :)

4
  • 2
    If you don't use Ubuntu in English, there's a change you will have to change the number in awk '{print $3}' to something else, for example I had to change it to awk '{print $2}'. Or you can change the locale to English (for FILE in $(LANG=en dpkg-divert --list | grep nvidia-340 | awk '{print $3}'); do dpkg-divert --remove $FILE; done).
    – Petr R.
    Jul 17, 2018 at 19:23
  • 3
    You've saved me from my agony, I've made an account here just to upvote
    – Primusa
    Mar 14, 2019 at 22:22
  • can you explain how this command is working, espacially LC_MESSAGES and sed -nre
    – vikrant
    May 12, 2020 at 9:59
  • life saver, this needs more upvotes.
    – sparkitny
    Feb 15, 2022 at 5:56
19

Here is the full answer in another forum

The basic premise of the answer is:

  1. you have old dependencies you want to remove
  2. you want to clean mess
  3. you want to install new driver

I assume you have cr*p from the 340 driver installed - which was my problem

  1. remove old dependencies

    LC_MESSAGES=C dpkg-divert --list '*nvidia-340*' | sed -nre 's/^diversion of (.*) to .*/\1/p' | xargs -rd'\n' -n1 -- sudo dpkg-divert --remove
    
  2. clean mess - depended on mess you have installed find it out if not work out of the box ;)

    sudo dpkg --force-all -P nvidia-390 nvidia-compute-utils-390 nvidia-dkms-390 nvidia-prime nvidia-settings nvidia-opencl-icd-340 nvidia-opencl-icd-384 nvidia-kernel-source-390 nvidia-kernel-common-390 libnvidia-cfg1-390 libnvidia-common-390 libnvidia-compute-390 libnvidia-decode-390 libnvidia-encode-390  libnvidia-fbc1-390 libnvidia-ifr1-390
    sudo apt purge --autoremove '*nvidia*'
    sudo apt-get update
    sudo apt-get upgrade
    
  3. install new recommended drivers

    ubuntu-drivers devices
    nvidia-settings
    

My advice is:
do not play with settings in this cr*ppy drivers just for checking if installed :)

5
  • 3
    Please don’t suggest dpkg --force-all for no good reason! The encountered abortions on error are meant to protect the integrity of the package management system and shouldn’t be suppressed without thought or care! -1 Oct 17, 2018 at 9:30
  • This works. I must comment: i detected that issue arise when 4k display used - then you have a boot problems. How i detected: replug old monitor and it booted easily Dec 24, 2018 at 14:06
  • I did #1 and then sudo apt install -f and sudo apt upgrade. worked.
    – ICE
    Feb 10, 2019 at 4:24
  • Why is this answer nearly the same as Lucas Serafim's answer? Aug 28, 2019 at 12:39
  • After changing my video card that was using nvidia 340, I tried to enable nvidia driver 390 from additional drivers. It failed because of this questions' error. For me it worked with your first command + sudo apt --fix-broken install because your second command gave error: The following packages have unmet dependencies: libnvidia-gl-390:i386 : Depends: libnvidia-common-390:i386. I did not had to reinstall the 390 driver. Jan 8, 2022 at 9:42
10

I solved the problem by removing nvidia-340's divert. hopefully I don't need to use nvidia-340. Following is an example:

dpkg-divert --package nvidia-340 --remove /usr/lib/i386-linux-gnu/libGL.so.1

You can keep on removing whenever you have a conflict.

2
  • Thanks a ton! At first, it looks like it's not working, but if we keep trying and removing, eventually it solves. Thanks again. May 27, 2018 at 8:55
  • Huge thanks! I could not get past this issue without knowing that I could modify the dpkg-divert list for nvidia-340 junk. You rock
    – Mikis
    Mar 22, 2019 at 15:33
3

Run this first,

Solution #for FILE in $(dpkg-divert --list | grep nvidia-340 | awk '{print $3}'); do dpkg-divert --remove $FILE; done

Then install it from ppa,

sudo add-apt-repository ppa:graphics-drivers/ppa 
sudo apt update 
sudo apt install nvidia-390

this worked for me on Ubuntu 18.04 LTS

3
  • The nvidia-driver-390 is in the default Ubuntu 18.04 repositories so what's the point of adding a PPA?
    – karel
    May 25, 2019 at 8:24
  • @karel If the guy is anything like me, I know that after I've spent hours or even days with a problem, and then found an answer that works, I don't keep restoring the problem back and seeing if I can remove a line from the solution that works, to see if it still works. As he said "this worked for me". I would love for you to provide more information on a quicker way of fixing this type of problem, which I am having right now, and getting no responses from the various problems I have. The only response was to tell me to stop posting about the same problem in two different ways.
    – brewmanz
    Feb 10, 2020 at 0:01
  • @brewmanz I could close vote those questions as duplicate questions because I've seen that dpkg-divert error message about a hundred times, but you think we're ignoring you. I'm ignoring you because you multiple posted the same question, and then you complained that you're being ignored by the same reviewers that are letting you get away with it. I'm equally frustrated whenever I read a high quality question that is misunderstood by its reviewers or isn't upvoted.
    – karel
    Feb 10, 2020 at 3:24
2

I would run apt auto-clean and see if its what I think it is, a messed up package.

sudo apt auto-clean
sudo apt update
sudo apt upgrade
sudo apt install nvidia-driver-390 libvulkan1

edit: to answer your other question, when I installed 18.04 the other day 390 worked fine, but going to 396 was a bit "fun". This fixed it for me.

2
  • Thanks a lot. This is as far as I got.: (I think I might do a clean reinstall) :~$ sudo apt upgrade Reading package lists... Done Building dependency tree Reading state information... Done You might want to run 'apt --fix-broken install' to correct these. The following packages have unmet dependencies. libnvidia-ifr1-390 : Depends: libnvidia-gl-390 but it is not installed libnvidia-ifr1-390:i386 : Depends: libnvidia-gl-390:i386 but it is not installed nvidia-driver-390 : Depends: libnvidia-gl-390 (= 390.48-0ubuntu3) but it is not installed .... May 15, 2018 at 22:37
  • .... Recommends: libnvidia-gl-390:i386 (= 390.48-0ubuntu3) E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution). May 15, 2018 at 22:42
1

as per: https://forums.developer.nvidia.com/t/problem-with-apt-and-nvidia-440-on-ubuntu-20-04/115281/4

It worked for me to 'fix' the broken deb (you can get the broken deb name if you run the update from the commandline eg. with aptitude)

sudo dpkg -i --force-overwrite /var/cache/apt/archives/libnvidia-extra-455_455.45.01-0ubuntu1_amd64.deb

After that, you can continue to fix other broken installs or just upgrade normally again

You must log in to answer this question.

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