Cuda Toolkit 9.1 on Ubuntu 16.04: installation failed

Dear all,

I’m really new into the Ubuntu world and I’m not able to install the Cuda Toolkit9.1 requested by my application.
I downloaded it from the website and type this command:
sudo sh cuda_9.1.85_387.26_linux.run

The installation seems to begin but at the end, there is an error message:

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 387.26?
(y)es/(n)o/(q)uit: y

Do you want to install the OpenGL libraries?
(y)es/(n)o/(q)uit [ default is yes ]: y

Do you want to run nvidia-xconfig?
This will update the system X configuration file so that the NVIDIA X driver
is used. The pre-existing X configuration file will be backed up.
This option should not be used on systems that require a custom
X configuration, such as systems with multiple GPU vendors.
(y)es/(n)o/(q)uit [ default is no ]: 

Install the CUDA 9.1 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-9.1 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 9.1 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/unloc ]: 

Installing the NVIDIA display driver...
It appears that an X server is running. Please exit X before installation. If you're sure that X is not running, but are getting this error, please delete any X lock files in /tmp.

===========
= Summary =
===========

Driver:   Installation Failed
Toolkit:  Installation skipped
Samples:  Installation skipped

Thanks for your help
Sébastien

You need to execute init 3 mode to proceed with X driver installation;
Otherwise use deb/ppa methods:



But you will have to remove installed nvidia components most likely:
http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#handle-uninstallation
Refer to https://devtalk.nvidia.com/default/topic/1000340/cuda-setup-and-installation/-quot-nvidia-smi-has-failed-because-it-couldn-t-communicate-with-the-nvidia-driver-quot-ubuntu-16-04/post/5243047/#5243047