Skip to content

Instantly share code, notes, and snippets.

Last active January 22, 2023 00:10
What would you like to do?
Auto-installer for CUDA Toolkit inside WSL2
#! /usr/bin/env bash
# Auto-installer for CUDA Toolkit inside Windows Subsystem for Linux.
if [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]
echo "ERROR: Only tested on Bourne-Again SHell v4/v5."
exit 1
fi >&2
main() {
installcuda() {
cudakeyring 1.0-1
cudatoolkit 12-0
# and some extra dev stuff suggested by deps above?
#sudo apt install autoconf automake libtool flex bison gdb
cudakeyring() {
local rev="$1"
! dpkg-query --list cuda-keyring ||return 0
local ckrdeb="cuda-keyring_${rev}_all.deb"
wget -N "$ckrdeb"
sudo dpkg --install "$ckrdeb"
rm "$ckrdeb"
cudatoolkit() {
local rev="$1"
local repometa=(/var/lib/apt/lists/*)
if [ "${#repometa[@]}" -eq 0 ]
then sudo apt update
#sudo apt install cuda
# DANGER! do not install cuda pacakge as it contains driver that will break WSL2's stub
# just the CUDA Toolkit and dependencies
! dpkg-query --list "cuda-toolkit-$rev" ||return 0
sudo apt install "cuda-toolkit-$rev"
return 2>/dev/null ||:
shopt -s nullglob
set -ex
exit 0
# After reading all the crap on
# I gave up on all the silly steps below and wrote the much smarter script above.
#wget -N
#wget -N
# both above are the same duh?
# why is this massive beast needed?
#wget -N
#wget -N
#sudo mv /etc/apt/preferences.d/cuda-repository-pin-600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment