This post describes how to install nvidia drivers, CUDA and cuDNN for ubuntu.
Prerequisites
Note: Make sure to check version compatibility between drivers.
Install Nvidia Drivers
You can install nvidia drivers when you install CUDA. But If you want to install
a specific version of the nvidia drivers, download it from official website,
or download it directly using wget
. For example,
$ wget http://us.download.nvidia.com/XFree86/Linux-x86_64/418.56/NVIDIA-Linux-x86_64-418.56.run
CUDA
Download runfile from the official website. I selected Linux-x86_64-Ubuntu-16.04-runfile (local). Or, you can also run the following line.
$ wget https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.168_418.67_linux.run
cuDNN
Download cuDNN from here. You need to have an nvidia developer account to download it. Download cuDNN 1. Runtime, 2. Developer, and 3. Code Samples and User Guide for Ubuntu 16.04 (The last one is optional).
Installation
Step 1. Nvidia drivers
Note: Install dkms
before installation (sudo apt-get install dkms
).
- Stop
lightdm
and enter into text login mode.$ sudo service stop lightdm $ sudo init 3
- Install nvidia drivers
$ sudo sh NVIDIA-Linux-x86_64-418.56.run --dkms --no-opengl-files --no-x-check
When there is a problem installing the drivers (e.g.
"You appear to be running an X server"
),--no-x-check
gives you detail error, such as"nvidia-uvm appears to already be loaded in your kernel"
. And if there is such error, run the following command:$ sudo stop nvidia-digits-server $ sudo service nvidia-docker stop $ sudo rmmod nvidia-uvm
Step 2. Install CUDA
- Run following command, and select only CUDA toolkit.
$ sudo sh cuda_10.1.168_418.56.run
Step 3. Install cuDNN
- Install runtime, developer, code samples and the cuDNN library User Guide (optional) with following lines.
$ sudo dpkg -i libcudnn7_7.6.0.64-1+cuda10.1_amd64.deb $ sudo dpkg -i libcudnn7-dev_7.6.0.64-1+cuda10.1_amd64.deb $ sudo dpkg -i libcudnn7-doc_7.6.0.64-1+cuda10.1_amd64.deb
Step 4. Set Environment Variables
- Prepend cuda path to
LD_LIBRARY_PATH
andPATH
path in.zshrc
or.bashrc
.$ vim ~/.zshrc
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH" export PATH="/usr/local/cuda/bin:$PATH"
Leave a comment