Skip to content

Instantly share code, notes, and snippets.

@maruel
Last active November 6, 2021 14:46
Show Gist options
  • Save maruel/e99622298891cc856044e8c158a83fdd to your computer and use it in GitHub Desktop.
Save maruel/e99622298891cc856044e8c158a83fdd to your computer and use it in GitHub Desktop.
Script to install CUDA and libcudnn on Ubuntu 20.04
#/bin/bash
# Copyright 2021 Marc-Antoine Ruel. No rights reserved.
# Official version at https://gist.github.com/maruel/e99622298891cc856044e8c158a83fdd
#
# Used the following as reference:
# - https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network
# - https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html
# - https://youtu.be/BXFGEGO8UY0
#
# I recommend looking at all 3 references before moving on.
set -eu
# First, install the Ubuntu native "server" nvidia drivers via the GUI application.
# At the time of writing it is nvidia-driver-470. After running the following I
# got nvidia-driver-495 so YMMV. Also note that for recent graphic cards you
# generally need a recent (read: buggy) driver.
# Want something recent? lolsob.
OS='ubuntu2004'
# The following code tries to pin too much. Reconsider not pinning at all.
cudnn_version='8.3.0.*'
cuda_version='cuda11.5'
# Should we pin? Not sure.
wget https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/cuda-${OS}.pin
sudo mv cuda-${OS}.pin /etc/apt/preferences.d/cuda-repository-pin-600
# What's really important:
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/ /"
sudo apt-get update
# Notice how cuda and libcunn8 use different ways to pin. Folks at nvidia should talk to each other.
sudo apt-get -y install cuda
sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version}
sudo apt-get install libcudnn8-dev=${cudnn_version}-1+${cuda_version}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment