105

On Ubuntu 18.04 I am getting this when I want to install the recommended Nvidia driver.

sudo apt install nvidia-340
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libargtable2-0 libass5 libavcodec-ffmpeg56 libavdevice-ffmpeg56
  libavfilter-ffmpeg5 libavformat-ffmpeg56 libavresample-ffmpeg2
  libavutil-ffmpeg54 libbluray1 libboost-random1.58.0 libboost-regex1.58.0
  libboost-thread1.58.0 libcryptopp-dev libethereum libfdk-aac0 libjsoncpp1
  libjsonrpccpp-client0 libjsonrpccpp-common0 libjsonrpccpp-server0
  libleveldb1v5 libmicrohttpd10 libmicrohttpd12 libnvidia-common-396
  libopencv-core2.4v5 libopencv-imgproc2.4v5 libopenjpeg5 libpostproc-ffmpeg53
  libschroedinger-1.0-0 libsdl-ttf2.0-0 libswresample-ffmpeg1
  libswscale-ffmpeg3 libtbb2 libva1 libx264-148 libx265-79 miniupnpc
  nvidia-kernel-common-396 nvidia-kernel-source-396 nvidia-prime php7.1-common
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  nvidia-340
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
Need to get 0 B/51,9 MB of archives.
After this operation, 274 MB of additional disk space will be used.
(Reading database ... 345463 files and directories currently installed.)
Preparing to unpack .../nvidia-340_340.107-0ubuntu0~gpu18.04.1_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
Removing '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'
diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340
Removing 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340'
diversion of /usr/lib/x86_64-linux-gnu/libGL.so to /usr/lib/x86_64-linux-gnu/libGL.so.distrib by nvidia-340
Removing 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so to /usr/lib/x86_64-linux-gnu/libGL.so.distrib by nvidia-340'
diversion of /usr/lib/i386-linux-gnu/libGL.so to /usr/lib/i386-linux-gnu/libGL.so.distrib by nvidia-340
Removing 'diversion of /usr/lib/i386-linux-gnu/libGL.so to /usr/lib/i386-linux-gnu/libGL.so.distrib by nvidia-340'
diversion of /usr/lib/x86_64-linux-gnu/libEGL.so.1 to /usr/lib/x86_64-linux-gnu/libEGL.so.1.distrib by nvidia-340
Removing 'diversion of /usr/lib/x86_64-linux-gnu/libEGL.so.1 to /usr/lib/x86_64-linux-gnu/libEGL.so.1.distrib by nvidia-340'
diversion of /usr/lib/i386-linux-gnu/libEGL.so.1 to /usr/lib/i386-linux-gnu/libEGL.so.1.distrib by nvidia-340
Removing 'diversion of /usr/lib/i386-linux-gnu/libEGL.so.1 to /usr/lib/i386-linux-gnu/libEGL.so.1.distrib by nvidia-340'
diversion of /usr/lib/x86_64-linux-gnu/libEGL.so to /usr/lib/x86_64-linux-gnu/libEGL.so.distrib by nvidia-340
Removing 'diversion of /usr/lib/x86_64-linux-gnu/libEGL.so to /usr/lib/x86_64-linux-gnu/libEGL.so.distrib by nvidia-340'
diversion of /usr/lib/i386-linux-gnu/libEGL.so to /usr/lib/i386-linux-gnu/libEGL.so.distrib by nvidia-340
Removing 'diversion of /usr/lib/i386-linux-gnu/libEGL.so to /usr/lib/i386-linux-gnu/libEGL.so.distrib by nvidia-340'
diversion of /usr/lib/x86_64-linux-gnu/libGLESv2.so to /usr/lib/x86_64-linux-gnu/libGLESv2.so.distrib by nvidia-340
Removing 'diversion of /usr/lib/x86_64-linux-gnu/libGLESv2.so to /usr/lib/x86_64-linux-gnu/libGLESv2.so.distrib by nvidia-340'
diversion of /usr/lib/i386-linux-gnu/libGLESv2.so to /usr/lib/i386-linux-gnu/libGLESv2.so.distrib by nvidia-340
Removing 'diversion of /usr/lib/i386-linux-gnu/libGLESv2.so to /usr/lib/i386-linux-gnu/libGLESv2.so.distrib by nvidia-340'
diversion of /usr/lib/x86_64-linux-gnu/libGLESv2.so.2 to /usr/lib/x86_64-linux-gnu/libGLESv2.so.2.distrib by nvidia-340
Removing 'diversion of /usr/lib/x86_64-linux-gnu/libGLESv2.so.2 to /usr/lib/x86_64-linux-gnu/libGLESv2.so.2.distrib by nvidia-340'
diversion of /usr/lib/i386-linux-gnu/libGLESv2.so.2 to /usr/lib/i386-linux-gnu/libGLESv2.so.2.distrib by nvidia-340
Removing 'diversion of /usr/lib/i386-linux-gnu/libGLESv2.so.2 to /usr/lib/i386-linux-gnu/libGLESv2.so.2.distrib by nvidia-340'
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'
Adding 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340'
Adding 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so to /usr/lib/x86_64-linux-gnu/libGL.so.distrib by nvidia-340'
Adding 'diversion of /usr/lib/i386-linux-gnu/libGL.so to /usr/lib/i386-linux-gnu/libGL.so.distrib by nvidia-340'
Adding 'diversion of /usr/lib/x86_64-linux-gnu/libEGL.so.1 to /usr/lib/x86_64-linux-gnu/libEGL.so.1.distrib by nvidia-340'
Adding 'diversion of /usr/lib/i386-linux-gnu/libEGL.so.1 to /usr/lib/i386-linux-gnu/libEGL.so.1.distrib by nvidia-340'
Adding 'diversion of /usr/lib/x86_64-linux-gnu/libEGL.so to /usr/lib/x86_64-linux-gnu/libEGL.so.distrib by nvidia-340'
Adding 'diversion of /usr/lib/i386-linux-gnu/libEGL.so to /usr/lib/i386-linux-gnu/libEGL.so.distrib by nvidia-340'
Adding 'diversion of /usr/lib/x86_64-linux-gnu/libGLESv2.so to /usr/lib/x86_64-linux-gnu/libGLESv2.so.distrib by nvidia-340'
Adding 'diversion of /usr/lib/i386-linux-gnu/libGLESv2.so to /usr/lib/i386-linux-gnu/libGLESv2.so.distrib by nvidia-340'
Adding 'diversion of /usr/lib/x86_64-linux-gnu/libGLESv2.so.2 to /usr/lib/x86_64-linux-gnu/libGLESv2.so.2.distrib by nvidia-340'
Adding 'diversion of /usr/lib/i386-linux-gnu/libGLESv2.so.2 to /usr/lib/i386-linux-gnu/libGLESv2.so.2.distrib by nvidia-340'
Unpacking nvidia-340 (340.107-0ubuntu0~gpu18.04.1) ...
dpkg: error processing archive /var/cache/apt/archives/nvidia-340_340.107-0ubuntu0~gpu18.04.1_amd64.deb (--unpack):
 trying to overwrite '/lib/udev/rules.d/71-nvidia.rules', which is also in package nvidia-kernel-common-396 396.45-0ubuntu0~gpu18.04.2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nvidia-340_340.107-0ubuntu0~gpu18.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

How do I get past this?

Nitescu Lucian
  • 1,382
  • 3
  • 11
  • 24

2 Answers2

249

Press Ctrl+Alt+T and do:

sudo dpkg -i --force-overwrite /var/cache/apt/archives/nvidia-340_340.107-0ubuntu0~gpu18.04.1_amd64.deb

This will resolve "the trying to overwrite error" with the mighty force of dpkg. :)

Then run:

sudo apt -f install

to fix if any broken packages.

Olimjon
  • 7,292
  • 7
    Wow, worked like a charm! How do you learn about this stuff? – Autodidact Mar 02 '20 at 05:02
  • @Autodidact, I do not remember, sorry. :( – Olimjon Mar 04 '20 at 01:51
  • 1
    @Autodidact, it's in the docs. Try man dpkg and the line in 18.04 looks like this: "overwrite: Overwrite one package's file with another's file." – Alexis Wilke May 10 '20 at 04:19
  • 3
    @AlexisWilke that is not a very efficient way to learn anything now is it. You can't just read entire man pages just in case. There are endless of them. Even if you did, you wouldn't be able to remember anything. I mean if it was the actual command they used, sure. You would look at the help section when you have trouble but there is no way, for someone who doesn't already know the answer is there, to predict which man page the answer is hidden. – timuçin Nov 13 '20 at 00:02
  • @Autodidact they probably previously learned what overwriting means in this context in a completely different scenario. Then, if they knew what dpkg does, they could figure out that this can be accomplished as such. Cheers – timuçin Nov 13 '20 at 00:06
  • 5
    @timuçin When I started on Unix, that's pretty much all I had, man pages to learn how to use the system... That being said, the error above includes the name dpkg so you could at least try a man dpkg and do some searches to see if you can find details. overwrite is one of the words in there. I think that's a good habit to have, but even I am guilty to look on the Internet instead of man pages. That being said, those pages are on the net. – Alexis Wilke Nov 13 '20 at 02:17
  • thank you very much!!! – Nezir Mar 01 '21 at 09:32
  • 1
    I had to run sudo apt purge <pacakge> after the above command then again sudo apt install <pacakge> to make it works – Maduka Jayalath Jun 03 '21 at 10:05
  • Sometimes need --auto-deconfigure if there are still dependencies – jeffmcneill Aug 08 '21 at 02:31
  • thanks, it helped me alot. – mujad Apr 28 '22 at 21:20
  • getting this error with mongodb – chovy Jun 02 '22 at 07:25
  • Works for me too, I'm install python3.9. Wonder if this command is dangerous? – Yan King Yin Aug 13 '22 at 11:46
  • Worked for a broken Emacs installation – tafchad Jan 09 '23 at 19:32
4

This process can also occur during upgrading ('sudo apt upgrade'). dpkg has in this case errors processing /tmp/apt-dpkg-install-some/file.deb, which does not exists after the upgrade in the /tmp directory. This .deb file does however exist in the /var/cache/apt/archives and the solution of Olimjon can be applied for this .deb file.

This resolved for me the issue for a program for which the repository was renamed from 'abiout' to 'agate'.

What is happening (at least in my case) is that some renamings or other changes in library files have to be enforced because dpkg do not recognize them as belonging to the same package/program. I guess something like this happened during the installation of the nvidia drivers.

Josja
  • 125