Install CUDA(9.1) and cuDNN on pure Ubuntu16

Welcome to my GitHub

Here is a classification and summary of all original works of Xinchen (including supporting source code):

Overview of this article

  • I have a 2015 Lenovo laptop with a graphics card of GTX950M and ubuntu 16.04 LTS desktop version installed. In order to use its GPU to complete the training of deeplearning4j, I installed CUDA and cuDNN by myself. I will record the whole process here for future reference. For reference, the entire installation process is divided into the following steps:
  1. Preparation
  2. Install Nvidia driver
  3. Install CUDA
  4. Install cuDNN

Special Issue Description

  • According to the general steps, after installing the Nvidia graphics card driver, the corresponding CUDA version will be prompted, and then install CUDA according to the prompted version. For example, the prompt here is 11.2. Under normal circumstances, I should install the 11.2 version of CUDA
  • But I choose version 9.1 to install, because in the previous development, I found that after deeplearning4j uses the 11.2 SDK, there will be a ClassNotFound error when starting the application. When the Nvidia driver prompts version 11.2, version 9.1 is still installed, and then the deeplearning4j application runs normally in this environment.
  • If you don’t have such problems like mine, you can install CUDA according to the version specified by the driver. The specific operation steps will be described in detail later;


  • The following operations, except for downloading on the webpage, are performed by remotely connecting to the ubuntu machine with ssh. The account logged in with ssh is an ordinary account, not root
  • If there is an existing driver, please delete it first:
sudo apt-get remove --purge nvidia*
  • Disable the nouveau driver (very important), open the file /etc/modprobe.d/blacklist.conf with vi, add the following content at the end, and save quit:
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
  • Turn off nouveau:
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
  • update initramfs:
update-initramfs -u
  • Execute reboot to restart the computer
  • After restarting, execute the following command, there should be no output, proving that nouveau has been disabled:
lsmod|grep nouveau
  • Get Kernel source:
sudo apt-get install linux-source
  • The information displayed during the installation process is as follows:
  • According to the information in the red box above, the kernel version number is , so execute the following command:
sudo apt-get install linux-headers-4.4.0-210-generic

Download and install Nvidia driver

  • Visit the Nvidia website, address, and then select the corresponding graphics card and operating system. My choices are as follows As shown in the figure:
  • After clicking the Search button in the above picture, enter the following page and click to download:
  • The downloaded file name is
  • Close the graphics page:
sudo service lightdm stop
  • Add executable permissions to the driver file:
sudo chmod a+x
  • start installation:
sudo ./ -no-x-check -no-nouveau-check -no-opengl-files
  • When encountering the following picture, select the red box:
  • When you encounter the following picture, press Enter directly:
  • Restore graphics page:
sudo service lightdm start
  • Execute the command nvidia-smi, if the driver is installed successfully, the following will be displayed:
will@lenovo:~/temp/202106/20$ nvidia-smi
Sun Jun 20 09:02:11 2021
 + ------------------------------------------------- ---------------------------- +
| NVIDIA-SMI 460.84 Driver Version: 460.84 CUDA Version: 11.2 |
|------------------------------- + ----------------- ----- + ---------------------- +
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=================================+ ================== ===== + =======================|
| 0 GeForce GTX 950M Off | 00000000:01:00.0 Off | N/A |
| N/A 41C P0 N/A / N/A | 0MiB / 4046MiB | 1% Default |
| | | N/A |
 + ------------------------------- + ----------------- ----- + ---------------------- +
 + ------------------------------------------------- ---------------------------- +
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|==================================================== ===============================|
| No running processes found |
 + ------------------------------------------------- ---------------------------- +
  • It can be seen from the above content that CUDA Version: 11.2 indicates that the corresponding CUDA version of the driver should be 11.2, as mentioned earlier, my I’m running into issues, so version 9.1 will be installed next, but you can choose to install 11.2

Install CUDA

  • Visit in the browser, and click the link in the red box:
  • Download the Linux version as shown below:
  • Continue to select x86_64:
  • Select a specific Linux version and its version number:
  • There are quite a few things to download, an installer and three patches:
  • The download addresses of the above four files are organized as follows: 2CmTa8z3Q390_6urlgc6LqjoqlIFW9gvfvDCusnINYplLaw1u8lRY8R4oVNtpNzaXU4BQcHjvdb6c6rjq20dktCcRd4640woXt1yHmD95v1Du7wdBBXq2eOY T2sDWscX20CJbdOwpkt30kWb9vx8E4oIlajDQ3MVPvXdiKKsIOBUx-h0q0N0jSkNn80VMhW-nk8jwvRY_e6MuFzqWBaPk 8eFh4aShBVUTmuPaasvRiMCKDZw5yjjIobGQrCEyU-LFO59AbrRER57Mxa0T1Sc97fC80IOZq8Ox2repjn7A3oYVgd8 dpArt8frjGHH2MeVn5TefMoclam8udm-RSMMmqHXYE66hHN2D0drVEdtCwe8ZrEIYb2rpucaz9svCFE8Z319mge4Ju94
  • After the download is complete, execute the command chmod a + x *.run to add executable permissions to the above four files
  • Install CUDA:
sudo sh
  • When encountering a license, like using the vi tool, enter “:”, then enter “q” and press Enter, you can skip the license reading and perform the real installation operation:
  • Next is a series of questions. The answer to each question is as shown in the figure below. Be sure to choose n for the questions in the red box:
  • After the installation completes output the following:
Installing the CUDA Toolkit in /usr/local/cuda-9.1 ...
Missing recommended library:
Missing recommended library:
Missing recommended library:
Missing recommended library:
Missing recommended library:

Installing the CUDA Samples in /home/will...
Copying samples to /home/will/NVIDIA_CUDA-9.1_Samples now...
Finished copying samples.


Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-9.1
Samples: Installed in /home/will, but missing recommended libraries

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

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.1/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.1/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 9.1 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver

Logfile is /tmp/cuda_install_13425.log
  • Open the file ~/.bashrc, and add the following two lines at the end (if LD_LIBRARY_PATH already exists, please refer to PATH and change it to append):
export PATH=/usr/local/cuda-9.1/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64
  • Execute the command source ~/.bashrc to make the configuration take effect
  • Execute the command su – to switch to the root account, and execute the following command (do not use sudo, but switch to the root account):
sudo echo "/usr/local/cuda-9.1/lib64" >> /etc/
  • Then execute the following command as root:
  • Execute the command exit to exit the root identity, and now it is an ordinary account again
  • Execute the command nvcc -V to check the CUDA version, note that the parameter V is capitalized:
will@lenovo:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
  • Install the first patch:
sudo sh
  • Install the second patch:
sudo sh
  • Install the third patch:
sudo sh

Install cuDNN

  • Browser visit
  • Follow the prompts to log in. If you don’t have an account, please register one. After logging in, you will enter the download page. You need to click the red box in the picture below to see the old version:
  • Choose the version that matches CUDA:
  • After downloading, unzip to get the folder cuda, and then execute the following command:
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a + r /usr/local/cuda/include/cudnn.h
sudo chmod a + r /usr/local/cuda/lib64/libcudnn*
  • Execute the command cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 to check and confirm. If the installation is successful, the following output will appear:
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 1

#include "driver_types.h"
  • So far, the installation of CUDA (9.1) and cuDNN on Ubuntu 16 has been completed, and I hope it can give you some references.

You are not alone, Xinchen Original is with you all the way

  1. Java series
  2. Spring series
  3. Docker series
  4. kubernetes series
  5. Database + middleware series
  6. DevOps series