Ubuntu 20.04 Installs nvidia drivers, Cuda, Cudnn

Keywords: sudo Linux Ubuntu


Updated ubuntu20.04, the interface was good and the feeling was fine, so I started my Alchemy environmental configuration journey.

1. Driver

  • Remember that BIOS shuts down Secure Boot. [Important]

  • Disable nouveau

sudo gedit /etc/modprobe.d/blacklist.conf

Add on last line

blacklist nouneau


sudo update-initramfs -u


lsmod | grep nouveau # No output means disable takes effect and will be executed after restart
  • Query your own graphics card model
lshw -numeric -C display
sudo chmod a+x NVIDIA-Linux-x86_64-418.43.run
sudo ./NVIDIA-Linux-x86_64-418.43.run --no-opengl-files --no-x-check --no-nouveau-check

--no-opengl-files only installs driver files, not OpenGL files.This parameter is most important

- no-x-check does not check X services when installing drivers

- no-nouveau-check does not check Nouveau when installing drivers

(If installed (e.g. me), it is recommended to overwrite the installation directly)

  • Verify successful installation, command nvidia-smi

2. Cuda

  • from https://developer.nvidia.com/cuda-toolkit-archive Download the corresponding version of cuda and select 18.04.
  • gcc downgrade The GCC version that comes with Ubuntu 20.04 is 9.7.0. You need to add gcc7 to install cuda10.2. Enter the command to install gcc7.
sudo apt install gcc-7 g++-7

Looking at the gcc version, you can see that there are 7 and 9 versions in the current system

ls /usr/bin/gcc*

Use update-alternatives for version switching, enter the following command:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50

Enter at this time

sudo update-alternatives --config gcc

The command looks at the default version of gcc and you can see that the current default version of gcc is 7, which means the switch was successful.

  • Install cuda
sudo  ./cuda_10.2.89_440.33.01_linux.run

Click continue

Enter accept

[X] CUDA Toolkit

The cuda package is driven by its own graphics card, so this step removes the option to install the graphics card driver by pressing the space and then chooses install

  • Configuring environment variables Enter the gedit ~/.bashrc command to open the file, enter the following statement at the end of the file, and save.
export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Update environment variable configuration

 source ~/.bashrc

Now that the cuda installation is complete, enter the nvcc-V command to view the cuda information

3. Cudnn

from https://developer.nvidia.com/cudnn To download cuDNN Library for Linux, you need to log in. After downloading the unzipped file, copy the cuda/include/cudnn.h file to the usr/local/cuda/include folder.

sudo cp ./cuda/include/cudnn.h /usr/local/cuda/include

Copy all files under cuda/lib64/to the/usr/local/cuda/lib64 folder and add read permissions:

sudo cp ./cuda/lib64/* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

The cuDNN installation is now complete.

  • Verify Installation Terminal Input:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

Success is shown below:

#define CUDNN_MAJOR 7
#define CUDNN_MINOR 6

#include "driver_types.h"

The full text is complete.

Posted by ts10 on Sat, 16 May 2020 11:03:58 -0700