I am Charmie

メモとログ

CUDA 10.1 on Ubuntu 18.04

You should first check the compatibility between NVIDIA driver and CUDA here so that you can avoid installing/uninstalling wrong combinations of them. Also, you should check which version are supported by some applications. In my case, I use PyTorch 1.0 which binary package supports CUDA 10.0 :(

This post describes how to install CUDA 10.1 on Ubuntu 18.04. For further information, please check the official site.

Step 0. Preparation

$ sudo apt purge nvidia-*
$ sudo apt purge cuda-*
$ sudo apt autoremove
$ sudo apt install build-essential

Step 1. Download the installer
Let's first download the installer from this page.

Step 2. Install the drivers and libraries

$ sudo dpkg -i cuda-repo-ubuntu1804_10.1.105-1_amd64.deb
$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
$ sudo apt update
$ sudo apt-get install cuda

Step 3. Set the environmental variables
Add the following lines to .bashrc.

export PATH=/usr/local/cuda-10.1/bin:/usr/local/cuda-10.1/NsightCompute-2019.1${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Step 4. Install cuDNN
Download cuDNN Runtime and Developer Libraries from here and then install by the following command.
$ sudo dpkg -i libcudnn7_7.5.0.56-1+cuda10.1_amd64.deb
$ sudo dpkg -i libcudnn7-dev_7.5.0.56-1+cuda10.1_amd64.deb
$ sudo dpkg -i libcudnn7-doc_7.5.0.56-1+cuda10.1_amd64.deb