Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save X-TRON404/e9cab789041ef03bcba13da1d5176e28 to your computer and use it in GitHub Desktop.
Save X-TRON404/e9cab789041ef03bcba13da1d5176e28 to your computer and use it in GitHub Desktop.
Instructions for CUDA v11.7 and cuDNN 8.5 installation on Ubuntu 22.04 for PyTorch 1.12.1
#!/bin/bash
### steps ####
# verify the system has a cuda-capable gpu
# download and install the nvidia cuda toolkit and cudnn
# setup environmental variables
# verify the installation
###
### to verify your gpu is cuda enable check
lspci | grep -i nvidia
### If you have previous installation remove it first.
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*
# system update
sudo apt-get update
sudo apt-get upgrade
# install other import packages
sudo apt-get install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
# first get the PPA repository driver
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
# install nvidia driver with dependencies
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-get update
sudo apt full-upgrade
# installing CUDA-11.7
sudo apt install cuda-11-7
# setup your paths
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
# install cuDNN v11.7
# First register here: https://developer.nvidia.com/developer-program/signup
CUDNN_TAR_FILE="cudnn-linux-x86_64-8.5.0.96_cuda11-archive.tar.xz"
wget https://developer.download.nvidia.com/compute/redist/cudnn/v8.5.0/local_installers/11.7/cudnn-linux-x86_64-8.5.0.96_cuda11-archive.tar.xz
tar -xvf ${CUDNN_TAR_FILE}
# copy the following files into the cuda toolkit directory.
sudo cp -P cudnn-linux-x86_64-8.5.0.96_cuda11-archive/include/cudnn.h /usr/local/cuda-11.7/include
sudo cp -P cudnn-linux-x86_64-8.5.0.96_cuda11-archive/lib/libcudnn* /usr/local/cuda-11.7/lib64/
sudo chmod a+r /usr/local/cuda-11.7/lib64/libcudnn*
# reboot
sudo reboot
# Finally, to verify the installation, check
nvidia-smi
nvcc -V
# install Pytorch (an open source machine learning framework)
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
@ichxw
Copy link

ichxw commented Jul 8, 2023

I followed the instruction exactly to install nvidia driver and cuda on Ubuntu 22.04. But get different versions of installation. Below is the first two lines of nvidia-smi:

Fri Jul 7 22:30:59 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.54.03 Driver Version: 535.54.03 CUDA Version: 12.2 |

nvcc -V shows the correct version:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0

Do you know what could be the problem? Thank you.

Copy link

ghost commented Aug 13, 2023

Can you help me with this

ubuntu@ip-172-31-15-98:~/cuda$ sudo apt install cuda-11-7
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
libnvidia-extra-525 : Conflicts: libnvidia-extra
libnvidia-extra-535 : Conflicts: libnvidia-extra
libnvidia-gl-525 : Conflicts: libnvidia-gl
libnvidia-gl-535 : Conflicts: libnvidia-gl
nvidia-kernel-common-525 : Conflicts: nvidia-kernel-common
nvidia-kernel-common-535 : Conflicts: nvidia-kernel-common
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

@hypily123
Copy link

hypily123 commented Aug 17, 2023

Can you help me with this

ubuntu@ip-172-31-15-98:~/cuda$ sudo apt install cuda-11-7 Reading package lists... Done Building dependency tree... Done Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:

The following packages have unmet dependencies: libnvidia-extra-525 : Conflicts: libnvidia-extra libnvidia-extra-535 : Conflicts: libnvidia-extra libnvidia-gl-525 : Conflicts: libnvidia-gl libnvidia-gl-535 : Conflicts: libnvidia-gl nvidia-kernel-common-525 : Conflicts: nvidia-kernel-common nvidia-kernel-common-535 : Conflicts: nvidia-kernel-common E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

I met the same problem and solved it by running
sudo apt full-upgrade
before
sudo apt install cuda-11-7

@X-TRON404
Copy link
Author

Can you help me with this
ubuntu@ip-172-31-15-98:~/cuda$ sudo apt install cuda-11-7 Reading package lists... Done Building dependency tree... Done Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:
The following packages have unmet dependencies: libnvidia-extra-525 : Conflicts: libnvidia-extra libnvidia-extra-535 : Conflicts: libnvidia-extra libnvidia-gl-525 : Conflicts: libnvidia-gl libnvidia-gl-535 : Conflicts: libnvidia-gl nvidia-kernel-common-525 : Conflicts: nvidia-kernel-common nvidia-kernel-common-535 : Conflicts: nvidia-kernel-common E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

I met the same problem and solved it by running sudo apt full-upgrade before sudo apt install cuda-11-7

Thank you! I have made the changes in the gist.

@madtunebk
Copy link

madtunebk commented Sep 30, 2023

somehow here:

sudo apt install libnvidia-common-515
sudo apt install libnvidia-gl-515
sudo apt install nvidia-driver-515
<<
i got redirected to 535 driver no matter what i do, then /usr/local/cuda-11.7/ its empty

@ichxw
Copy link

ichxw commented Oct 11, 2023

somehow here:

sudo apt install libnvidia-common-515 sudo apt install libnvidia-gl-515 sudo apt install nvidia-driver-515 << i got redirected to 535 driver no matter what i do, then /usr/local/cuda-11.7/ its empty

Please take a look at this solution: https://github.com/ichxw/cuda_11.7_installation_on_Ubuntu_22.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment