lspci | grep -i nvidia
sudo apt-get purge nvidia*
sudo apt remove nvidia-*
sudo rm /etc/apt/sources.list.d/cuda*
sudo apt-get autoremove && sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*
sudo apt-get update
sudo apt-get upgrade
You can also use the GUI provided by Ubuntu to install the Nvidia Drivers
In Ubuntu search for "Additional Drivers", and install the one that's recommended
Additional_Drivers.webm
sudo apt install libnvidia-common-515
sudo apt install libnvidia-gl-515
sudo apt install nvidia-driver-515
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
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /"
sudo apt update
sudo apt install cuda-11-7
echo 'export PATH=/usr/local/cuda-11.7/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig
Use the following link to register and download the cuDNN Driver here: https://developer.nvidia.com/rdp/cudnn-archive
Download the one mentioned for CUDA v11.x
Nvidia_cuDNN.webm
After downloading the cuDNN deb file, navigate to the downloads folder
cd Downloads
And use the following command to install it
sudo apt install ./<name_of_file.deb>
use the following commands to copy the files to CUDA toolkit directory
sudo cp -P cuda/include/cudnn.h /usr/local/cuda-11.7/include
sudo cp -P cuda/lib/libcudnn* /usr/local/cuda-11.7/lib64/
sudo chmod a+r /usr/local/cuda-11.7/lib64/libcudnn*
nvidia-smi
nvcc -V
pip3 install torch torchvision torchaudio
use the following code in a python file and run it.
If it outputs "True" it is sucessfully installed
import torch
torch.cuda.is_available()
python3 -m pip install tensorflow==2.13.*
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
If the output is something like this, it shows TensorFlow has been installed sucessfully for GPU
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]