Can't login to Ubuntu after installing CUDA

Before you do anything else, write these two commands for escaping from a login loop on a piece of paper, so if you get stuck in a login loop when booting you will be able to do something about it.

  • sudo chown $(whoami):$(whoami) .Xauthority
  • sudo dpkg-reconfigure lightdm

Also write down the link to this answer which has more detailed information about how to get unstuck from a login loop.


Your problem may have been caused by the NVIDIA proprietary graphics driver that is bundled with the NVIDIA CUDA Toolkit from official NVIDIA CUDA Downloads website. So try using the NVIDIA proprietary graphics driver and NVIDIA CUDA Toolkit from the default Ubuntu repositories.

The NVIDIA CUDA Toolkit package from the default Ubuntu 16.04 repositories is version 7.5 which is not as up-to-date as the NVIDIA CUDA Toolkit 8.0 package from the official NVIDIA CUDA Downloads website, but is it more stable and reliable. The same goes for the proprietary NVIDIA graphics driver from the default Ubuntu 16.04 repositories, nvidia-346 or nvidia-352 or whatever other nvidia driver version is recommended for your hardware in Step 4. of the following instructions.

  1. Bring up a text-only virtual console from the login screen, using the keyboard combination Ctrl+Alt+F3 and then you will get a text-only virtual console which shows you a login prompt. Login to the console at the login prompt with your username and password.

  2. Run this command to show a list of cuda packages, that will help you to identify the name of the NVIDIA CUDA Toolkit package that you installed.

    dpkg-query -l cuda*  
    
  3. Uninstall the NVIDIA proprietary graphics driver from a text-only console. The file you used to install the NVIDIA CUDA Tookit from the NVIDIA website should be named something like cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb. If so, the command to uninstall it is:

    sudo dpkg -P cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64
    sudo reboot 
    

    If the file you used to install the NVIDIA CUDA Toolkit has a different name or if you installed a different file, then change the name in the above command. If you installed cuda_8.0.61_375.26_linux.run file (runfile (local)), then comment so that I can change the command to match this file. The name of the file in the above command has to match exactly with the name of the NVIDIA CUDA Toolkit file that you installed.

  4. After you reboot, uninstall all the CUDA packages you previously installed. They won't work properly without the NVIDIA proprietary driver from the NVIDIA website, so you will have to install the CUDA packages from the default Ubuntu repositories instead.

  5. Identify the recommended proprietary graphics driver for your system. Open the terminal and type:

    ubuntu-drivers devices  
    
  6. Install the recommended NVIDIA proprietary graphics driver and reboot.

    sudo apt install <package-name-of-the-recommended graphics-driver> 
    sudo reboot 
    
  7. Install the CUDA packages. Open the terminal and type:

    sudo apt install libcudart7.5 nvidia-cuda-toolkit  
    

P.S. I hope you didn't change any PATH variables in the terminal after you installed the CUDA package from the official NVIDIA CUDA Downloads website. If you did change the PATH variable from the terminal, please comment and let me know, so I can tell you how to change it back.


  • Press Ctrl+Alt+F3 to switch to a different terminal

  • Login

  • Uninstall nvidia* packages

sudo apt-get purge nvidia-*

  • After that, install nvidia-346

sudo apt-get install nvidia-346

  • reboot