This question already has an answer here:
I have a Dell with a Core I5 and a GeForce820M.
After upgrading to 18.04 LTS I tried to upgrade the nvidia drivers by running
sudo apt-get install nvidia-340
which is the recommended driver for my GPU.
The problem is the installation failed, I didn't record the fail reasons and now any
apt-get commands I try to run say that I should run
sudo dpkg --configure -a
I tried running that but it kept getting stuck at
Building initial module for 4.15.0-23-generic
Finally I managed to complete it, but when I tried to install the nvidia-340 package again I got an error:
Preparing to unpack .../nvidia-340_340.106-0ubuntu3_amd64.deb ... Adding '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: rename involves overwriting '/usr/lib/x86_64-linux-gnu/libGL.so.1.distrib' with different file '/usr/lib/x86_64-linux-gnu/libGL.so.1', not allowed dpkg: error processing archive /var/cache/apt/archives/nvidia-340_340.106-0ubuntu3_amd64.deb (--unpack): new nvidia-340 package pre-installation script subprocess returned error exit status 2 Errors were encountered while processing: /var/cache/apt/archives/nvidia-340_340.106-0ubuntu3_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)