Installing nvidia drivers on 18.04

Solution 1:

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 :)

Solution 2:

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 :)

Solution 3:

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.