Install CUDA

To install CUDA, download it here:

I downloaded 11.8.0.

Don't forget, you also need to decide which version of CUDA to install. Not all CUDA supports all driviers.

First you need know the verison of the driver via nvidia-smi. And query the doc to know which CUDA it supports:


	echo "Installing CUDA... Do NOT select the driver!!!"
	sudo sh ./

	echo "PATH=\"$PATH\"" | sudo tee /etc/environment > /dev/null

	source /etc/environment

	nvcc --version

Install cuDNN

To install cuDNN, download it here:

I downloaded Download cuDNN v8.9.0 (April 11th, 2023), for CUDA 11.x.


	echo "Installing CUDNN..."
	sudo dpkg -i ./cudnn-local-repo-ubuntu2204-
	sudo cp /var/cudnn-local-repo-*/cudnn-local-*-keyring.gpg /usr/share/keyrings/
	sudo apt-get update
	sudo apt-get install libcudnn8=
	sudo apt-get install libcudnn8-dev=
	sudo apt-get install libfreeimage-dev

Install PyTorch

DO NOT directly type pip install torch!!! The torch you installed may not be compatible with your CUDA and you may see error:

AssertionError: Torch not compiled with CUDA enabled

First open here: PyTorch

And finish this tutorial:


You may see a command:

pip3 install torch torchvision torchaudio --index-url

That should be the correct command to run.

How to tell if the driver is installed?



To get more details, like if it is licensed, run:

nvidia-smi -q

How to tell if CUDA is installed?


/usr/local/cuda/bin/nvcc --version


To test the CUDA, create a

#include <stdio.h>

__global__ void helloCUDA()
    printf("Hello CUDA from thread %d in block %d!\n", threadIdx.x, blockIdx.x);

int main()
    // 4 blocks, 8 threads per block
    int numBlocks = 4;
    int threadsPerBlock = 8;

    // launch kernel
    helloCUDA<<<numBlocks, threadsPerBlock>>>();

    // wait for device to finish

    return 0;

Now run it!

nvcc ./ -o hello-world && ./hello-world


How to tell if cuDNN is installed?


cat /usr/include/cudnn_version.h | grep CUDNN_M

To test it, run:

cp -r /usr/src/cudnn_samples_v8/ /tmp
cd  /tmp/cudnn_samples_v8/mnistCUDNN
make clean && make

If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:

Test passed!

How to tell if torch is installed?

Run python, and type:

import  torch