GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - milistu/cuda-cudnn-installation: How to install CUDA & cuDNN for Machine Learning

BranchesTags
Open more actions menu

Latest commit

 

History

17 Commits
17 Commits

Folders and files

NameName
Last commit message
Last commit date
README.md
README.md
 
 
test.py
test.py
 
 

Repository files navigation

How to install CUDA & cuDNN

Setting up CUDA & cuDNN for Machine Learning can be overwhelming. In this guide, I will walk you through the steps to install CUDA and cuDNN on your system, ensuring your machine is correctly set up for deep learning tasks. 

System Configuration:

  • Operating System: Ubuntu 22.04
  • GPU: GeForce RTX 3090
  • ML Framework: PyTorch

Install NVIDIA drivers

Update & Upgrade

sudo apt update && sudo apt upgrade

Remove previous NVIDIA installation

Uninstall the previous NVIDIA and CUDA installation to avoid messing up the new installation.

sudo apt-get remove --purge -y '*nvidia*' '*cuda*' 'libcudnn*' 'libnccl*' '*cudnn*' '*nccl*'
sudo apt-get autoremove --purge -y
sudo apt-get clean

Check if there are any remaining packages or files.

dpkg -l | grep -E 'nvidia|cuda|cudnn|nccl'

Detecting and Managing Drivers on Ubuntu

ubuntu-drivers devices

We will install the NVIDIA driver tagged recommended, which indicates which drivers are recommended for each piece of hardware based on compatibility and performance.

Install Ubuntu drivers

sudo ubuntu-drivers autoinstall

Install NVIDIA drivers

My recommended version is nvidia-driver-595-open. If ubuntu-drivers devices recommends a different driver on your machine, replace nvidia-driver-595-open with that package name.

sudo apt install nvidia-driver-595-open

Reboot the system for these changes to take effect.

reboot

Check Installation

After reboot, verify that the following command works:

nvidia-smi

Install CUDA drivers

Update & Upgrade

Again, check for updates on your OS.

sudo apt update && sudo apt upgrade

Install CUDA Toolkit

At the time of writing, the latest CUDA version supported by PyTorch is 13.2.

You can find older versions in the CUDA Toolkit Archive. In my case, I will be continuing with CUDA Toolkit 13.2.0 (March 2026).

You will need to select your operating system (Linux in my case). Afterwards, you will be prompted to select the Architecture. If you are not sure what the Architecture of your PC you can use the command below (in my case, the Architecture is x86_64).

uname -m

Next, we need to select the distribution and version of our operating system, in my case, Ubuntu 22.04. Lastly, I am using the deb (local) installer type.

These are the commands for installing CUDA Toolkit 13.2:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/13.2.0/local_installers/cuda-repo-ubuntu2204-13-2-local_13.2.0-595.45.04-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-13-2-local_13.2.0-595.45.04-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-13-2-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-13-2

Check CUDA install

nvcc --version

If you are not getting the CUDA version as output, do the following:

  • Ensure that CUDA 13.2 is installed in the correct directory, typically /usr/local/cuda-13.2.
  • Create a symlink to the CUDA directory to make it easier to reference.
    sudo ln -s /usr/local/cuda-13.2 /usr/local/cuda
  • Add the CUDA paths to your .bashrc file to ensure they are set up every time you open a terminal.
    echo 'export PATH=/usr/local/cuda-13.2/bin:$PATH' >> ~/.bashrc
  • Apply the changes made to the .bashrc
    source ~/.bashrc

Install cuDNN

Download the cuDNN .deb file

Firstly, to match appropriate cuDNN with our CUDA and Driver versions, we can use the table provided by NVIDIA. In my case, the newest 9.22.0 cuDNN version is appropriate.

You can download the cuDNN file here, for which you will need an Nvidia account. Same as for CUDA, you will have to select OS, architecture, distribution, version, and installer type.

In my case, to download the installer for Linux Ubuntu 22.04 x86_64, the instructions are as follows:

wget https://developer.download.nvidia.com/compute/cudnn/9.22.0/local_installers/cudnn-local-repo-ubuntu2204-9.22.0_1.0-1_amd64.deb
sudo dpkg -i cudnn-local-repo-ubuntu2204-9.22.0_1.0-1_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2204-9.22.0/cudnn-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cudnn9-cuda-13

Test CUDA with PyTorch

I assume that you already have Python installed on your machine, so this tutorial will not cover that part.

⚠️ NOTE: The latest PyTorch requires Python 3.10 or later.

Create a Directory

mkdir test_cuda
cd test_cuda

Create and Activate a Virtual Environment

python -m venv .venv
source .venv/bin/activate

Install PyTorch

pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu132

Execute Python test script

import torch


# Check PyTorch version
print(f"PyTorch version: {torch.__version__}")
# Check if CUDA device is recognised
print(f"CUDA device is available: {torch.cuda.is_available()}")
assert torch.cuda.is_available(), ValueError("CUDA device is not recognised.")

device = "cuda"
a = torch.rand(3, 1).to(device)
b = torch.rand(1, 3).to(device)

c = a @ b

print(f"Variable shape: {c.shape}")
print(f"Variable device: {c.device}")

Conclusion

If you carefully followed these instructions, you have successfully installed CUDA and cuDNN on your Ubuntu 22.04 system. Your NVIDIA GPU is now ready for deep learning tasks with PyTorch.

You can also view this guide on Medium. If this guide helped you, give it a 👏, share it, and give it a ⭐️ on GitHub.

About

How to install CUDA & cuDNN for Machine Learning

medium.com/@milistu/how-to-install-cuda-cudnn-7e4a00ae4f44

Topics

cudacudnndeepgpumachine-learningnvidiapythonpytorch

Resources

Readme
Activity

Stars

21 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.