Try   HackMD

Ubuntu 18.04 CUDA/cuDNN Installation

Step 1. Remove older version of CUDA/CuDNN

  • Go to /usr/local/ see if there are any cuda-x.x folder. Then remove it with:

    ​​​​sudo rm -rf /usr/local/cuda-x.x/

Step 2. Install CUDA

  • Download from https://developer.nvidia.com/cuda-toolkit
    Choose the way with your environment,
    last step choose deb(local)

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More β†’

  • Follow the instruction

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More β†’

    In this time, like this:

    ​​​​wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin ​​​​sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 ​​​​wget https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb ​​​​sudo dpkg -i cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb ​​​​sudo apt-key add /var/cuda-repo-ubuntu1804-11-2-local/7fa2af80.pub ​​​​sudo apt-get update ​​​​sudo apt-get -y install cuda
  • After installation complete, add below PATH variable to the shellrc you use:
    https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#mandatory-post

    ​​​​export PATH=/usr/local/cuda-11.2/bin${PATH:+:${PATH}} ​​​​export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64\${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} ​​​​export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/targets/x86_64-linux/lib
  • CUDA installed

Step 3. Install CuDNN

Official Installation Guide: https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#installlinux

  • Download from https://developer.nvidia.com/rdp/cudnn-archive

    Select the support version of CUDA (this time I used is CUDA11.2 & cuDNN8.1.0)
    Choose cuDNN Library for Linux(x86_64)

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More β†’

  • After downloaded, extract it and copy to the right place

    ​​​​tar -xzvf cudnn-x.x-linux-x64-v8.x.x.x.tgz ​​​​sudo cp cuda/include/cudnn*.h /usr/local/cuda/include ​​​​sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64 ​​​​sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
  • Verify Version

    ​​​​cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR
  • cuDNN installed