This article aims to be a guideline for installation of CUDA Toolkit on Linux. Target environment of this guideline is CUDA 9.1 and Ubuntu 17.10, however it can be applicable to other systems. Actually, it’s not a rocket science, but there are certain points which require extra attention and those points are completely distributive-independent.

0. Pay attention to system requirements

Official installation guide for Linux defines system requirements which you must conform to make things work. This might be obvious that everyone should get familiar with system requirements before installing anything on a target system. However it is easy to lull your vigilance if you are working basically with software in the modern world of constant changes and updates.

So, pay special attention to supported versions of kernel and gcc. If your existing installation differs from the recommended one, you must be able to decide whether you are OK to upgrade/downgrade your kernel and whether it’s possible for you to install required version of gcc.

1. Manage kernel version

CUDA is a device architecture which is implemented inside GPU. It allows to create a heterogeneous computing architecture, where CPU acts as a supervisor and GPU takes role of a workhorse. Thus, CPU and GPU need to talk to each other and such communication is done via driver. As Linux implements microkernel architecture where drivers are treated as plugins, they must be compatible with the kernel which they are going to be plugged into.

Unfortunatelly, Nvidia’s drivers are source-closed and you cannot compile them for your kernel version. Hence, you are left to use what you are given. If driver is not compatible with your kernel, you have to change the kernel.

As official documentation states, supported version of kernel for Ubuntu 17 is 4.9. Well, Ubuntu 17.10 is shipped with kernel 4.13 and downgrading it to version 4.9 may look too aggressive.

So, will it work with kernel 4.13? Actually, yes and no, it depends. Installation has failed for my version 4.13.0–32 and it has failed for version 4.13.26. Why? Well, there are bugs inside the kernel. For example, some functions may be used without includes of their headers and this results into compilation errors. While such issues are easy to fix, there are other errors which can drive you crazy.

Luckily, kernel 4.13.16 is suitable for CUDA 9.1 and no errors were observed.

I recommend to use UKUU to manage kernels on Ubuntu. You can stay without it, however personally I have found it to be very useful, as it allows you to do all job with few command-line instructions. Feel free to follow this article to get familiar with UKUU. In short installation looks like:

$ sudo ukuu --install v4.13.16

Don’t forget to reboot your system after switching to another kernel:

$ sudo reboot

After that make sure the kernel headers and development packages for the currently running kernel are installed:

$ sudo apt install linux-headers-$(uname -r)

$ sudo apt install build-essential

2. Check out GCC

CUDA needs gcc 6 for Ubuntu 17. The latter one comes with gcc 7. Required version can coexist with default one:

$ sudo apt install gcc-6

$ sudo apt install g++-6

3. Download the toolkit

Download process is straightforward: