Is there a PPA for having nvidia-cuda-toolkit with the latest cuda (11.1) for Ubuntu 20.04 (Focal)?

The official packages do not seem up-to-date (https://packages.ubuntu.com/search?keywords=nvidia-cuda-toolkit) but using the latest cuda seems to matter when using newer hardware.

Nvidia is making packages available, but there is no guarantee that they will work well or will integrate with Ubuntu’s management of nvidia drivers.

Is there an effort to create an ubuntu package in a PPA so we do not have to install manually and work out conflicts individually? (the package would handle that)

Asked By: lgautier

||
  1. Open the terminal and remove any NVIDIA traces that you may have on your system.

    sudo rm /etc/apt/sources.list.d/cuda*
    sudo apt remove --autoremove nvidia-cuda-toolkit
    sudo apt-get remove --autoremove nvidia-*
    
  2. Setup the correct CUDA PPA on your system.

    export DISTRO=ubuntu2004
    export ARCHITECTURE=x86_64
    sudo apt update
    sudo add-apt-repository ppa:graphics-drivers
    sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/${DISTRO}/${ARCHITECTURE}/7fa2af80.pub 
    sudo bash -c "echo deb http://developer.download.nvidia.com/compute/cuda/repos/${DISTRO}/${ARCHITECTURE}/ / > /etc/apt/sources.list.d/cuda.list"  
    sudo bash -c "echo deb http://developer.download.nvidia.com/compute/machine-learning/repos/${DISTRO}/${ARCHITECTURE} / > /etc/apt/sources.list.d/cuda_learn.list"  
    
  3. Install CUDA 11.1 packages.

    sudo apt update
    sudo apt -y install cuda-11-1
    sudo apt install libcudnn8
    
  4. Specify the PATH to CUDA in the ‘.profile’ file. Open the file by running sudo nano ~/.profile and add the following lines at the end of the file:

    # set PATH for cuda 11.1 installation
    if [ -d "/usr/local/cuda-11.1/bin/" ]; then
        export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
        export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    fi
    

    Use the keyboard combination Ctrl + O and after that press Enter to save the file to its current location. Use the keyboard combination Ctrl + X to exit nano.

  5. Restart with sudo reboot and check the versions of the installation.

    CUDA:

    nvcc  --version
    

    NVIDIA driver:

    nvidia-smi
    

    libcudnn:

    /sbin/ldconfig -N -v $(sed ‘s/:/ /’ <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn
    
Answered By: karel

Thanks karel for the answer. In step 2 I faced a GPG error: "public key is not available".

I followed the comment of jtran1999 in the nvidia issue 1632 to proporly add the key and the CUDA PPA. Maybe it’ll help others with the same error:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt-get update

Then continued for step 3 and everything worked fine!!

Answered By: Cristina Bazzano
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.