Unable to properly install/uninstall Cuda on Ubuntu 18.04

Hello, everyone! I recently got Ubuntu 18.04, and I tried to install Cuda in it. However, I am getting an error, and I am unable to uninstall it either! When I do

sudo apt-get install cuda

, it gives me this error (after it failed the first time):

Reading package lists... Done
Building dependency tree       
Reading state information... Done
cuda is already the newest version (9.1.85-1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies.
 cuda-drivers : Depends: nvidia-390 (>= 390.30) but it is not going to be installed
 libcuda1-390 : Depends: nvidia-390 (>= 390.30) but it is not going to be installed
 nvidia-390-dev : Depends: nvidia-390 (>= 390.30) but it is not going to be installed
 nvidia-opencl-icd-390 : Depends: nvidia-390 (>= 390.30) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

And then, I tried a couple of things:

sudo apt --fix-broken install

which gives this:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libbsd0:i386 libffi6:i386 libgl1:i386 libglvnd0:i386 libglx0:i386
  libnvidia-cfg1-390 libnvidia-fbc1-390 libnvidia-fbc1-390:i386
  libnvidia-gl-390:i386 libnvidia-ifr1-390 libnvidia-ifr1-390:i386
  libwayland-client0:i386 libwayland-server0:i386 libx11-6:i386
  libxau6:i386 libxcb1:i386 libxdmcp6:i386 libxext6:i386
  nvidia-dkms-390 nvidia-kernel-common-390 nvidia-kernel-source-390
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  nvidia-390
The following NEW packages will be installed
  nvidia-390
0 to upgrade, 1 to newly install, 0 to remove and 4 not to upgrade.
106 not fully installed or removed.
Need to get 0 B/76.5 MB of archives.
After this operation, 308 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 166161 files and directories currently installed.)
Preparing to unpack .../nvidia-390_390.30-0ubuntu1_amd64.deb ...
Unpacking nvidia-390 (390.30-0ubuntu1) ...
dpkg: error processing archive /var/cache/apt/archives/nvidia-390_390.30-0ubuntu1_amd64.deb (--unpack):
 trying to overwrite '/lib/udev/rules.d/71-nvidia.rules', which is also in package nvidia-kernel-common-390 390.48-0ubuntu3
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nvidia-390_390.30-0ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

and then,

sudo apt-get install nvidia*390

gives

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'nvidia-kernel-common-390' for glob 'nvidia*390'
Note, selecting 'nvidia-utils-390' for glob 'nvidia*390'
Note, selecting 'nvidia-dkms-390' for glob 'nvidia*390'
Note, selecting 'nvidia-headless-no-dkms-390' for glob 'nvidia*390'
Note, selecting 'nvidia-compute-utils-390' for glob 'nvidia*390'
Note, selecting 'nvidia-driver-390' for glob 'nvidia*390'
Note, selecting 'nvidia-libopencl1-390' for glob 'nvidia*390'
Note, selecting 'nvidia-headless-390' for glob 'nvidia*390'
Note, selecting 'nvidia-opencl-icd-390' for glob 'nvidia*390'
Note, selecting 'nvidia-kernel-source-390' for glob 'nvidia*390'
Note, selecting 'nvidia-390' for glob 'nvidia*390'
nvidia-dkms-390 is already the newest version (390.48-0ubuntu3).
nvidia-dkms-390 set to manually installed.
nvidia-kernel-common-390 is already the newest version (390.48-0ubuntu3).
nvidia-kernel-common-390 set to manually installed.
nvidia-kernel-source-390 is already the newest version (390.48-0ubuntu3).
nvidia-kernel-source-390 set to manually installed.
nvidia-opencl-icd-390 is already the newest version (390.30-0ubuntu1).
nvidia-opencl-icd-390 set to manually installed.
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies.
 nvidia-390 : Conflicts: nvidia-persistenced
              Conflicts: nvidia-smi
 nvidia-compute-utils-390 : Depends: libnvidia-compute-390 but it is not going to be installed
                            Conflicts: nvidia-persistenced
 nvidia-driver-390 : Depends: libnvidia-compute-390 (= 390.48-0ubuntu3) but it is not going to be installed
                     Depends: libnvidia-decode-390 (= 390.48-0ubuntu3) but it is not going to be installed
                     Depends: libnvidia-encode-390 (= 390.48-0ubuntu3) but it is not going to be installed
                     Depends: xserver-xorg-video-nvidia-390 (= 390.48-0ubuntu3) but it is not going to be installed
                     Recommends: libnvidia-compute-390:i386 (= 390.48-0ubuntu3)
                     Recommends: libnvidia-decode-390:i386 (= 390.48-0ubuntu3)
                     Recommends: libnvidia-encode-390:i386 (= 390.48-0ubuntu3)
 nvidia-headless-no-dkms-390 : Depends: libnvidia-compute-390 (= 390.48-0ubuntu3) but it is not going to be installed
 nvidia-libopencl1-390 : Conflicts: libopencl1
 nvidia-utils-390 : Depends: libnvidia-compute-390 but it is not going to be installed
                    Conflicts: nvidia-smi
 ocl-icd-libopencl1 : Conflicts: libopencl1
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

I don’t know how to fix this! Can somebody please help me?

I have totaly the same issue. I use Ubuntu 18.04, and i was trying to install cuda for Ubuntu 17.04 via web installer.

I have the same issue !

I have the same issue !
But I see someone installed succeed!!

I have the same issue :(
Then, I also changed the source type from network to local, but it went wrong with the same error.

Guys, I managed to get apt working again by removing the CUDA repository from software & updates. However, I am unable to install CUDA itself. Hope this helps people who at least want to get it uninstalled.

FYI
Don’t install Ubuntu 18.04 from scratch, it’s not a brilliant idea ;))

I ran into the same thing. I was able to finally get tensorflow working again with the network .deb file by installing just the toolkit:

sudo apt install cuda-toolkit-9-1

Before that I separately purged the nvidia packages and reinstalled nvidia-390 so that my screen display wasn’t stuck to 1024x720. I don’t know if that had anything to do with it.

You have to wait for CUDA 9.2 to release with hopefully support for Ubuntu 18.04.

In the meantime, you can simply run :

sudo apt install nvidia-cuda-toolkit

Here is my output from the apt-cache :

nvidia-cuda-toolkit:
      Installed: 9.1.85-3ubuntu1

The drivers dependencies are probably correct in apt’s repos but not in old Ubuntu .deb files

EDIT : I have drivers 390.48

I successfully installed it with the .run files. Install the driver with

sudo apt install nvidia-384

(which actually installs driver version 390), then download the .run file and install with:

sudo ./cuda_9.1.85_387.26_linux.run --verbose --silent --toolkit --override

You can also apply the patches as

sudo ./cuda_9.1.85.1_linux.run --silent --accept-eula
sudo ./cuda_9.1.85.2_linux.run --silent --accept-eula
sudo ./cuda_9.1.85.3_linux.run --silent --accept-eula

However CUDA 9.1 doesn’t support GCC7. So install GCC6:

sudo apt install gcc-6 g++-6

Then create symlinks to GCC6 in the CUDA bin folder:

sudo ln -s /usr/bin/gcc-6 /usr/local/cuda-9.1/bin/gcc
sudo ln -s /usr/bin/g++-6 /usr/local/cuda-9.1/bin/g++

Following on what @kriegalex wrote above:

What worked for me was the process described at https://medium.com/@taylordenouden/installing-tensorflow-gpu-on-ubuntu-18-04-89a142325138 plus the protobuf bit @dashsd provided above. $PATH and $LD_LIBRARY_PATH all use ‘/usr/local/cuda-9.0’.

The latter contains two separate entries, as described in https://github.com/tensorflow/tensorflow/issues/16750: one for /usr/local/cuda-9.0/extras/CUPTI/lib64 and another for /usr/local/cuda-9.0/lib64.

I use Ubuntu 18.04 on a Dell XPS 15" with NVIDIA GeForce GTX 1050 (GP107M), driver version 390.48. Tensorflow now runs on CUDA 9.0 and CUDNN 7.0.5.

For me, installing nvidia-390 and cuda-toolkit-9-2 separately works. The cuda-drivers package included in the meta package cuda tries to replace nvidia-390 (which is one of its own dependencies, as stated in the original error in this thread) with nvidia-396.

Since cuda-drivers also include some other packages besides the nvidia driver, if you need them, you will have to install them manually.

It looks like Ubuntu 18.04 fail to install with

apt-get

. For me, I use

sudo apt install cuda-9-0

install cuda9.0 successfully.

.

After a lot of googling and debugging, I finally found the main reason was I installed an older version of NVIDIA driver. I removed all packages in the driver using dpkg (apt keeps complaining to run “apt -f install” first, but it apparently is a dead loop. So I had to use dpkg). However I still encountered an error:

trying to overwrite '/usr/lib/x86_64-linux-gnu/libGLX_indirect.so.0', which is also in package libglx-mesa0:amd64 18.0.5-0ubuntu0~18.04.1

When I tried to remove libglx-mesa0, dpkg complains that a lot more packages depend on it. Seems it’s something essential. So instead I forced dpkg to overwrite the above file:

sudo dpkg -i <b>--force-overwrite</b> /var/cuda-repo-9-2-local/nvidia-396_396.37-0ubuntu1_amd64.deb

Now that nvidia-396 is successfully installed, and I could proceed with “apt -f install”.

Hi all, my “fix” was to switch to different Linux distributive, everything works fine now with NVidia 396, GCC 7 and latest cuDNN ;)

What linux distribution did you switch to?

@shaohua your tip helped! Thanks a lot. #14 https://devtalk.nvidia.com/default/topic/1032886/cuda-setup-and-installation/unable-to-properly-install-uninstall-cuda-on-ubuntu-18-04/post/5275081/#5275081

I installed:

cuda-repo-ubuntu1710-9-2-local_9.2.148-1_amd64.deb
cuda-repo-ubuntu1710-9-2-148-local-patch-1_1.0-1_amd64.deb

Post installation actions:
https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#post-installation-actions

$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module  396.37  Tue Jun 12 13:47:27 PDT 2018
GCC version:  gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)

Sorry for late response, hope my answer will help anybody. I switched to Manjaro (child of Arch Linux). It has rolled updates like Arch has.

I fix this issue only with this: sudo apt-get -o Dpkg::Options::="--force-overwrite" install --fix-broken

8 Likes

Neither local nor network installer succeed to install.

$ sudo apt-get install cuda
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cuda : Depends: cuda-10-1 (>= 10.1.105) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.