How do I Install CUDA on Ubuntu 18.04?

Is there any tutorial to install CUDA on Ubuntu 18.04?

The instructions on the Nvidia website for 17.04 and 16.04 do not work for 18.04.

I get a message telling me to reboot then re-run the installer. However when I do this I get that same message again.


Solution 1:

In a terminal, type:


sudo add-apt-repository ppa:graphics-drivers/ppa

sudo apt update

sudo ubuntu-drivers autoinstall

reboot


sudo apt install nvidia-cuda-toolkit gcc-6

nvcc --version

I have a gtx970 graphics card and a fresh install of Ubuntu 18.04

This worked for me

Solution 2:

I have installed CUDA 9.1 on Ubuntu 18.04, and runs very well.

I modify THE default gcc and g++, and use .run files instead of .deb files.

  1. Install gcc-6, g++-6 (CUDA requires gcc-6 !)

  2. In /usr/bin run

    sudo rm gcc, gcc-ar, gcc-nm, gcc-ranlib g++ 
    sudo ln -s gcc-6 gcc 
    sudo ln -s gcc-ar-6 gcc-ar 
    sudo ln -s gcc-nm-6 gcc-nm 
    sudo ln -s gcc-ranlib-6 gcc-ranlib 
    sudo ln -s g++-6 g++
    
  3. Install CUDA using .run files. Installing the latest driver (if required, download NVIDIA-Linux-xxxxxxx.run from Nvidia) would be better.

That's all.

I've tried to install using .deb files, but it causes package conflicts so I've switched to using this way.

Enjoy it!!

Solution 3:

Enable multiverse repository, install nvidia drivers and nvidia-cuda-toolkit and gcc6 (preferably using update-alternatives to easily switch versions):

  1. In software & updates, select the restricted and multiverse repositories
  2. In the Additional Drivers tab in software & updates select the NVIDIA proprietary driver (390 for CUDA 9)
  3. sudo apt update && sudo apt install nvidia-cuda-toolkit, or install it from the ubuntu software center.
  4. CUDA requires gcc6, use update-alternatives to maintain both gcc7 and gcc6 as explained here.

Alternatively you can follow Taylor's instructions:

  1. After installing the proprietary NVIDIA driver, download CUDA 9 installation from their site (get Ubuntu the 17.04 runfile version)
  2. make the downloaded file executable with sudo chmod +x
  3. run it with --override flag
  4. Accept the terms and conditions, say yes to installing with an unsupported configuration, and no to “Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?”. Make sure you don’t agree to install the new driver.
  5. See above about using gcc6

The second method has the downside that it's not as easy to upgrade or remove.

Solution 4:

I doubt the answers above qualify, because they seem to leave the system without the whole NVidia driver subsystem. I can guess why Cuda does not pull in the drivers, although I would probably prefer to have it otherwise. I am also not sure which is the proper way to get the latest driver, but right now this seems to do it:

sudo apt-get install nvidia-driver-390

Solution 5:

The CUDA toolkit finally released the 18.04 ubuntu support