61

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.

  • It worked for me. Which part of it doesn't work for you? – user3667089 Apr 27 '18 at 16:41
  • It says that a reboot is need and then re-run the installer, but I reboot the computer and try to reinstall and all I get is the same message... – Gabs Apr 27 '18 at 16:48
  • Try follow the instruction here which uses the runfile to install the driver and the cuda toolkit. – taper Aug 9 '18 at 16:23
19

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

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

  1. install gcc-6, g++-6 (CUDA requires gcc-6 !)
  2. In /usr/bin as root, rm gcc, gcc-ar, gcc-nm, gcc-ranlib g++, then ln -s gcc-6 gcc; ln -s gcc-ar-6 gcc-ar; ln -s gcc-nm-6 gcc-nm; ln -s gcc-ranlib-6 gcc-ranlib; and ln -s g++-6 g++
  3. install CUDA using .run files. You may not istall driver. Instead, install 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 conflict so that I've changed the way.

Enjoy it!!

97

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

  • 9
    This should be accepted answer – luboskrnac Aug 20 '18 at 12:29
  • 6
    This mostly worked for me. Only problem was ubuntu-drivers was not found and had to fix it by running: sudo apt-get install ubuntu-drivers-common (found it here: askubuntu.com/a/361868/766963) – Volkan Paksoy Sep 1 '18 at 11:02
  • This worked for me, though I had to switch back to nouveau from the UI before running autoinstall (it reported conflicts installing v396 while v390 was installed) – Alex Reinking Oct 12 '18 at 21:30
  • 1
    This worked perfectly. However sudo apt upgrade broke everything again, be careful with upgrades! – Luis Nov 15 '18 at 14:48
  • 1
    For me, the autoinstall command results in The following packages have unmet dependencies: nvidia-driver-415 – MrMartin Mar 5 at 11:57
12

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.

  • 2
    Although the link to the package page is useful, and there is enough information here that this isn't a "link-only answer" or anything, I do recommend that you edit this to explain how to do what you are recommending. – Eliah Kagan Apr 27 '18 at 16:56
5

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

  • 3
    Right, if you don't install the Nvidia drivers from the Ubuntu repositories, you may have to reinstall them after every kernel update. – ubfan1 Apr 28 '18 at 15:21
  • You probably also need nvidia-driver-390-dev – Mr.WorshipMe Apr 29 '18 at 18:30
4

This is what I did. There might be added extra stuff that I could have probably not had to do, but I am going to include it anyways.

First get the ppa repository drivers. (I would say this is required before installing, unless you want to risk some login loop of death).

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

Then install the latest driver. I use the GUI updater for the most part called Software & Updates, in the Additional Drivers tab. As of today nvidia driver 396 is available.

Get g++-6 and gcc-6. (Required)

sudo apt install g++-6
sudo apt install gcc-6

You can try using nvidia-cuda-toolkit, but the paths to the libraries wasn't familiar to me. I didn't want to mess with it.

(I would probably skip this one, but go to it if other stuff is giving issues)

sudo apt install nvidia-cuda-toolkit

I ended up installing the 9.1 run file for Ubuntu 17.04. Download it. Mark the file as executable(I right click on the file in desktop). Go into the terminal and put. (Required)

./cuda_9.1.85_387.26_linux.run --override

It will install it using the new gcc compilers. It will ask you a bunch of questions, and it will want them answered immediately.

Answer yes to the unsupported confguration.

No to the nvidia driver.

Yes- to the toolkit

I used default install locations

After that is installed then make sure you set up your paths. The run file will give you a reminder, too. Also the nvidia documentation will tell you what to export.

echo 'export PATH=/usr/local/cuda-9.1/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64:$LD_LIBRARY_PATH' >> ~/.bash.rc
source ~/.bashrc

Finally you have to set up simlinks to gcc-6 and g++-6 or you will get a warning on compiling your own code.(Required)

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

Reboot the system. (Required)

  • Good answer, but in my situation the Ubuntu repo nvidia driver was the wrong sub-version! At the time of posting this the nvidia-396 package is version 396.37 which doesn't work for my GeForce GTX 950. So I had to install 396.18 manually! So be sure to check the driver is the one you really need. – salotz Aug 29 '18 at 15:17
4

The CUDA toolkit finally released the 18.04 ubuntu support

2

Let's see how my answer for 16.04 goes:

  1. Download CUDA for Ubuntu 17.10 (runfile local) - Tensorflow recommends CUDA 9.0 - CUDA 9.2 seems not to work with tf
  2. Install CUDA requirements (see section below)
  3. Run sudo sh cuda_7.5.18_linux.run
  4. Follow the command line prompts.

Next step: Install cuDNN

CUDA 9.2

$ nvidia-smi
Fri Jun  8 18:09:24 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.48                 Driver Version: 390.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 940MX       Off  | 00000000:02:00.0 Off |                  N/A |
| N/A   72C    P0    N/A /  N/A |    512MiB /  2004MiB |     90%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1031      G   /usr/lib/xorg/Xorg                           276MiB |
|    0      3072      G   ...-token=0F06A89A68C1B8739F1AB9EF1C5654F9   232MiB |
+-----------------------------------------------------------------------------+

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Wed_Apr_11_23:16:29_CDT_2018
Cuda compilation tools, release 9.2, V9.2.88

Warning: Do not install the display driver! (At least it didn't work on my Thinkpad T460p)

CUDA 9.0 for tf

$ nvidia-smi
Sat Jun  9 08:55:30 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.48                 Driver Version: 390.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 940MX       Off  | 00000000:02:00.0 Off |                  N/A |
| N/A   68C    P0    N/A /  N/A |    595MiB /  2004MiB |     91%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1036      G   /usr/lib/xorg/Xorg                           350MiB |
|    0      2531      G   ...-token=FA7CF967F32AD2277A4B0EA78D1CB8D4   241MiB |
+-----------------------------------------------------------------------------+

and

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

CUDA Requirements

$ sudo apt-get install gcc-6 g++-6
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 50
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50

Verify with

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.4.0-17ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-as=/usr/bin/x86_64-linux-gnu-as --with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.4.0 20180424 (Ubuntu 6.4.0-17ubuntu1)
0

My own experience in CUDA installation. Tested on Ubuntu 18.04. Task:

  • Install graphical driver for Palit GeForce GTX 1080 Ti GameRock 11GB GDDR5X [NEB108TT15LC-1020G].
  • Install CUDA library for all users.

Related links:

NVIDIA driver installation

Go to NVIDIA web-site - https://www.nvidia.com/Download/index.aspx and obtain the latest driver for your GPU. In my case it is:

Product Type: GeForce
Product Series: GeForce 10 Series
Product: GeForce GTX 1080 Ti
Operating System: Linux 64-bit
Language: English (US)
Press <SEARCH> button and check that founded driver is supporting your GPU
in "SUPPORTED PRODUCTS" tab.

Download it. In my case filename is: NVIDIA-Linux-x86_64-410.78.run

# Change permission to run and execute it
sudo chmod +x NVIDIA-Linux-x86_64-410.78.run

# Before installation install gcc and make packages:
sudo apt install gcc
sudo apt install make

It is better to run driver installation in the text mode. For the text mode press <Ctrl>+<Alt>+<F3> and login to console.

Most likely you'll have problems with previously installed graphical driver called Nouveau.

# Remove Nouveau driver
sudo apt –purge remove xserver-xorg-video-nouveau
# Remove previously installed NVIDIA driver
sudo apt purge nvidia*

# Execute file and answer the questions during installation
sudo ./NVIDIA-Linux-x86_64-410.78.run

# Reboot Ubuntu
sudo reboot

# To check if installation is successful
nvidia-smi

You should see terminal output of Nvidia Drivers: enter image description here

# Check again
lsmod | grep nouveau  # should be zero output
lsmod | grep nvidia   # should be non-zero output

# Another check. {tab} means you should press <Tab> button on your keyboard.
cat /proc/driver/nvidia/gpus/{tab}/information

You should see correct model of your GPU: enter image description here

Installing CUDA library for all users

# Install gcc, kernel headers and development libraries
sudo apt install gcc-6 g++-6 linux-headers-$(uname -r) freeglut3-dev libxmu-dev libpcap-dev

Download CUDA toolkit from - https://developer.nvidia.com/cuda-downloads Select: Linux, x86_64, Ubuntu, 18.04, runfile (local).

Download 2.0 GB file: cuda_10.0.130_410.48_linux.run

# Change permissions and run it
sudo chmod +x cuda_10.0.130_410.48_linux.run
sudo ./cuda_10.0.130_410.48_linux.run

If installation is successful, your should see the following output:
===========
= Summary =
===========

Toolkit: Installed in /usr/local/cuda-10.0
Samples: Not Selected

Please make sure that
 - PATH includes /usr/local/cuda-10.0/bin
 - LD_LIBRARY_PATH includes /usr/local/cuda-10.0/lib64, or, add /usr/local/cuda-10.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To configure the CUDA environment for all users (and applications) on your system create two files (use sudo and a text editor of your choice)

# Create file cuda.sh
sudo touch /etc/profile.d/cuda.sh
# Open cuda.sh file
sudo nano /etc/profile.d/cuda.sh
# Add content to the file
export PATH=$PATH:/usr/local/cuda/bin
export CUDADIR=/usr/local/cuda

# Also create file cuda.conf
sudo touch /etc/ld.so.conf.d/cuda.conf
# Open cuda.conf file
sudo nano /etc/ld.so.conf.d/cuda.conf
# Add content to the file
/usr/local/cuda/lib64

# Restart ldconfig
sudo ldconfig

# Create symbolic links to GCC6 in the CUDA bin folder.
sudo ln -s /usr/bin/gcc-6 /usr/local/cuda-10.0/bin/gcc
sudo ln -s /usr/bin/g++-6 /usr/local/cuda-10.0/bin/g++

# Test CUDA by building the examples
# Copy the CUDA samples source directory to someplace in your home directory
# Go to the directory with the samples and run:
make -j4

# There could be compilation error for the samples
# Error: cannot find -lGL
# I was able to fix it by following the instructions in this link:
# http://techtidings.blogspot.com/2012/01/problem-with-libglso-on-64-bit-ubuntu.html (the final two commands)
sudo rm /usr/lib/x86_64-linux-gnu/libGL.so
sudo ln -s /usr/lib/libGL.so.1 /usr/lib/x86_64-linux-gnu/libGL.so

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.