This occurs in 18.04 because versions 340 and 390 are attempted to be installed at the same time and they apparently both want to modify /lib/udev/rules.d/71-nvidia.rules
apt-get install -f was not able to fix the situation.
Workaround: remove all packages mentioning nvidia 340 and 390 (beware you may want to check what this does):
# show the packages we're about to remove
dpkg-query -W | egrep 'nvidia.*3[49]0' | perl -naE 'say $F[0]'
# remove them
dpkg-query -W | egrep 'nvidia.*3[49]0' | perl -naE 'say $F[0]' | sudo xargs dpkg -P
Now install *ONLY* the version 340 one. And then both apt and subsequently the nvidia driver worked for me.
This occurs in 18.04 because versions 340 and 390 are attempted to be installed at the same time and they apparently both want to modify /lib/udev/ rules.d/ 71-nvidia. rules
apt-get install -f was not able to fix the situation.
Workaround: remove all packages mentioning nvidia 340 and 390 (beware you may want to check what this does):
# show the packages we're about to remove
dpkg-query -W | egrep 'nvidia.*3[49]0' | perl -naE 'say $F[0]'
# remove them
dpkg-query -W | egrep 'nvidia.*3[49]0' | perl -naE 'say $F[0]' | sudo xargs dpkg -P
Now install *ONLY* the version 340 one. And then both apt and subsequently the nvidia driver worked for me.