NVIDIA driver problem after apt upgrade ubuntu 18.04

I have a problem after apt upgrade ang get this message:

 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.87-0ubuntu0~gpu18.04.1) but it is not installed
                     Recommends: libnvidia-gl-390:i386 (= 390.87-0ubuntu0~gpu18.04.1)
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

After that I try apt --fix-broken install, but I get:

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.87-0ubuntu0~gpu18.04.1_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.87-0ubuntu0~gpu18.04.1_amd64.deb ...
diversion of /usr/lib/x86_64-linux-gnu/libGL.so to /usr/lib/x86_64-linux-gnu/libGL.so.distrib by nvidia-340
dpkg-divert: error: mismatch on package
  when removing 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so by libnvidia-gl-390'
  found 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so to /usr/lib/x86_64-linux-gnu/libGL.so.distrib by nvidia-340'
dpkg: error processing archive /var/cache/apt/archives/libnvidia-gl-390_390.87-0ubuntu0~gpu18.04.1_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.87-0ubuntu0~gpu18.04.1_i386.deb
 /var/cache/apt/archives/libnvidia-gl-390_390.87-0ubuntu0~gpu18.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Then I try solution from how to fix this apt problem on ubuntu 18.04 LTS?

sudo rm /var/cache/apt/archives/libnvidia-gl-390_390.87-0ubuntu0~gpu18.04.1_i386.deb
sudo rm /var/cache/apt/archives/libnvidia-gl-390_390.87-0ubuntu0~gpu18.04.1_amd64.deb

then to erase all of the downloaded files in your cache.

sudo apt-get clean
sudo apt-get autoremove && sudo apt-get autoclean

And again I got:

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.87-0ubuntu0~gpu18.04.1) but it is not installed
                     Recommends: libnvidia-gl-390:i386 (= 390.87-0ubuntu0~gpu18.04.1)
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

I update ubuntu from version 16.04 to 18.04 3 weeks ago - but this problem appeared two days ago.

Can anyone help?


It most likely didn't install correctly. I'd probably remove the packages without dependencies like so:

sudo dpkg -r libnvidia-ifr1-390
sudo dpkg -r libnvidia-ifr1-390:i386
sudo dpkg -r nvidia-driver-390

Using those commands should free up apt-get, now you can install the dependencies and reinstall the driver: (This should install the dependencies automatically)

sudo apt-get install nvidia-driver-390

And if the same thing happens again, try this: (This installs the listed dependencies and the driver)

sudo apt-get install libnvidia-gl-390:i386
sudo apt-get install libnvidia-gl-390
sudo apt-get install nvidia-driver-390

Or this: (This uninstalls and purges anything installed related to Nvidia and installs the driver while also deleting local copies of packages to download it again)

sudo apt-get clean
sudo apt-get purge nvidia*
sudo apt-get autoremove --purge
sudo apt-get install nvidia-driver-390