Forked from MihailCosmin/cuda_11.8_installation_on_Ubuntu_22.04
Last active
June 12, 2024 16:19
-
-
Save vitorcalvi/39c72a6f7d74a55d01f2b0df0bdfcfb4 to your computer and use it in GitHub Desktop.
Instructions for CUDA v11.8 and cuDNN 8.7 installation on Ubuntu 22.04 for PyTorch 2.0.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
### | |
# Function to print messages | |
print_message() { | |
echo -e "\n" | |
echo "###############################################" | |
echo "# \$1" | |
echo "###############################################" | |
echo -e "\n" | |
} | |
print_message "Verifying if the system has a CUDA-capable GPU" | |
lspci | grep -i nvidia | |
print_message "Removing previous NVIDIA installations" | |
sudo apt purge -y nvidia* | |
sudo apt remove -y nvidia-* | |
sudo rm /etc/apt/sources.list.d/cuda* | |
sudo apt autoremove -y && sudo apt autoclean -y | |
sudo rm -rf /usr/local/cuda* | |
print_message "Updating the system" | |
sudo apt update && sudo apt upgrade -y | |
print_message "Installing essential packages" | |
sudo apt install -y g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev | |
print_message "Adding PPA repository for graphics drivers" | |
sudo add-apt-repository -y ppa:graphics-drivers/ppa | |
sudo apt update | |
print_message "Finding recommended driver versions" | |
ubuntu-drivers devices | |
print_message "Installing NVIDIA driver with dependencies" | |
sudo apt install -y nvidia-driver-535 nvidia-kernel-source-535 | |
print_message "Reboot the system to load the new NVIDIA driver" | |
sudo reboot now | |
# After reboot, continue the installation | |
print_message "Verifying NVIDIA driver installation" | |
nvidia-smi | |
print_message "Downloading and setting up CUDA repository" | |
sudo 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/ /" | |
print_message "Updating the system again" | |
sudo apt update && sudo apt upgrade -y | |
print_message "Installing CUDA 11.8" | |
sudo apt install -y cuda-11-8 | |
print_message "Setting up environment variables for CUDA" | |
echo 'export PATH=/usr/local/cuda-11.8/bin:$PATH' >> ~/.bashrc | |
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc | |
source ~/.bashrc | |
sudo ldconfig | |
print_message "Downloading and installing cuDNN v8.7.0 for CUDA 11.8" | |
CUDNN_TAR_FILE="cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz" | |
wget https://developer.download.nvidia.com/compute/redist/cudnn/v8.7.0/local_installers/11.8/${CUDNN_TAR_FILE} | |
tar -xvf ${CUDNN_TAR_FILE} | |
sudo cp -P cudnn-linux-x86_64-8.7.0.84_cuda11-archive/include/cudnn*.h /usr/local/cuda-11.8/include | |
sudo cp -P cudnn-linux-x86_64-8.7.0.84_cuda11-archive/lib/libcudnn* /usr/local/cuda-11.8/lib64/ | |
sudo chmod a+r /usr/local/cuda-11.8/lib64/libcudnn* | |
print_message "Installing NVIDIA CUDA Toolkit" | |
sudo apt install -y nvidia-cuda-toolkit | |
print_message "Verifying the installation" | |
nvidia-smi | |
nvcc -V | |
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) | |
print_message "Setting up NVIDIA Docker repository and installing NVIDIA Docker" | |
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - | |
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list | |
print_message "Updating the system again" | |
sudo apt-get update | |
print_message "Installing NVIDIA Docker" | |
sudo apt-get install -y nvidia-docker2 | |
print_message "Restarting Docker" | |
sudo systemctl restart docker |
sudo apt install python3-pip -y
pip install huggingface_hub
python -c "from huggingface_hub.hf_api import HfFolder; HfFolder.save_token('MY_HUGGINGFACE_TOKEN_HERE')"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Add the repository to Apt sources:
echo
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin