# Install cuDNN on WSL2 Ubuntu 22.04

**URL:** <https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236>\
**Category:** cuDNN\
**Created:** [May 8, 2024, 7:14pm UTC](https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236 "2024-05-08T19:14:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ciro.rosa](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ciro.rosa](https://forums.developer.nvidia.com/u/ciro.rosa)\
**Post date:** [May 8, 2024, 7:14pm UTC](https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236/1 "2024-05-08T19:14:19Z")

</div>

Cheers,

I’ve installed successfully the cuda toolkit by following [this](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#wsl) link, which points out to wsl-ubuntu/x86\_64/ repository.

When trying to install cuDNN, instructions found [here](https://docs.nvidia.com/deeplearning/cudnn/v9.1.0/installation/linux.html#ubuntu-debian-network-installation) point out to ubuntu2204/x86\_64/ repository, but not to the one from above. Thus, the repository is not installed. As a result, when issuing the below command, installation fails, as the corresponding file is not found at the wsl repository.

`sudo apt-get -y install cudnn9-cuda-12`

Please kindly advise. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![AakankshaS](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aakankshas/32/14047_2.png) [@AakankshaS](https://forums.developer.nvidia.com/u/AakankshaS)\
**Post date:** [May 31, 2024, 8:37am UTC](https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236/2 "2024-05-31T08:37:09Z")

</div>

Hi,  
Can you please check if you have another wsl instance present on your machine?

---

<div class="post-metadata">

**Author:** ![ciro.rosa](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ciro.rosa](https://forums.developer.nvidia.com/u/ciro.rosa)\
**Post date:** [June 4, 2024, 4:59pm UTC](https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236/3 "2024-06-04T16:59:10Z")

</div>

Cheers,

Indeed, I do have another two instances, installed by Docker.

Regards,

Ciro.

---

<div class="post-metadata">

**Author:** ![moosarazeek](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@moosarazeek](https://forums.developer.nvidia.com/u/moosarazeek)\
**Post date:** [June 14, 2024, 3:09pm UTC](https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236/4 "2024-06-14T15:09:36Z")

</div>

Bro it says,  
E: Unable to locate package cudnn9-cuda-12

Any solutions.

---

<div class="post-metadata">

**Author:** ![siruijiang3](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@siruijiang3](https://forums.developer.nvidia.com/u/siruijiang3)\
**Post date:** [January 11, 2025, 5:40am UTC](https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236/5 "2025-01-11T05:40:54Z")

</div>

If you first installed CUDA for WSL and then installed cuDNN, note that since cuDNN does not provide a dedicated online repository for WSL, you need to check whether you are still using the software source configured for WSL. The repository specifically designed for WSL does not include cuDNN.

---

<div class="post-metadata">

**Author:** ![jaai0123210](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jaai0123210](https://forums.developer.nvidia.com/u/jaai0123210)\
**Post date:** [March 3, 2025, 10:09pm UTC](https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236/6 "2025-03-03T22:09:43Z")

</div>

So in that case, what solution is there. No cudnn through wsl2?

---

<div class="post-metadata">

**Author:** ![divinity76](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/divinity76/32/416118_2.png) [@divinity76](https://forums.developer.nvidia.com/u/divinity76)\
**Post date:** [May 17, 2025, 6:17am UTC](https://forums.developer.nvidia.com/t/install-cudnn-on-wsl2-ubuntu-22-04/292236/7 "2025-05-17T06:17:12Z")

</div>

@jaai0123210 Amazingly, I cannot run cuDNN on WSL2 directly, but I can run CuDNN inside docker containers inside WSL2.

In WSL2 Install the package `docker.io` (! important, not `docker` but `docker.io` !) and `nvidia-container-toolkit` (this is required for `docker run --gpus` to work)  
then set up a docker container like

```bash
mkdir mountdir;
docker run --gpus all -dit \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    --network=host \
    --shm-size=5g \
    --name "${CONTAINER_NAME}" \
    -v "${MOUNT_DIR}":/mountdir \
    ubuntu:24.04 bash

docker exec -i "${CONTAINER_NAME}" bash <<'EOF'

set -eux

export DEBIAN_FRONTEND=noninteractive

apt update;

apt full-upgrade -y;

apt install tzdata;

ln -fs /usr/share/zoneinfo/Europe/Oslo /etc/localtime

echo "Europe/Oslo" > /etc/timezone

dpkg-reconfigure -f noninteractive tzdata;

apt install screen screenie nano vim sudo wget curl htop php-cli python3 python-is-python3 python3-venv git build-essential cmake python3-dev -y;

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb;

dpkg -i cuda-keyring_1.1-1_all.deb;

apt update;

apt -y install cuda-toolkit-12-9;

apt -y install cudnn;

echo 'export PATH="/usr/local/cuda-12.9/bin:$PATH"' >> ~/.bashrc;

echo 'export LD_LIBRARY_PATH="/usr/local/cuda-12.9/lib64:$LD_LIBRARY_PATH"' >> ~/.bashrc;

echo 'export CUDA_HOME="/usr/local/cuda-12.9"' >> ~/.bashrc;
mkdir -p /root/.local/venv;
python3 -m venv /root/.local/venv;
echo 'source /root/.local/venv/bin/activate;' >> ~/.bashrc;
EOF

```

Then access the container like

```bash
docker exec -it "${CONTAINER_NAME}" bash

```

and.. inside that container,  
cudnn works great!  
and nvtop works great!  
and python AI libraries work great!

But it does not work outside docker containers (wtf?)

Fwiw here is the _exact_ setup that works for me:

```bash
hans@DESKTOP-EE15SLU:~/projects/rembg_model$ cat docker.sh 
#!/bin/bash
set -eux
CONTAINER_NAME="rembg_model_trainer"

# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"

# Create mount directory if it does not exist
MOUNT_DIR="$(pwd)";
mkdir -p "${MOUNT_DIR}"

# Check if the container exists
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
    # Check if the container is running
    if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
        echo "Container '${CONTAINER_NAME}' is already running. Attaching..."
        docker exec -it "${CONTAINER_NAME}" bash
    else
        echo "Container '${CONTAINER_NAME}' exists but is not running. Starting and attaching..."
        docker start -ai "${CONTAINER_NAME}"
    fi
else
    # Run the container in detached mode
    #-p 7011:7011/tcp -p 7011:7011/udp \
    docker run --gpus all -dit \
        -e DISPLAY=$DISPLAY \
        -v /tmp/.X11-unix:/tmp/.X11-unix \
        --network=host \
        --shm-size=5g \
        --name "${CONTAINER_NAME}" \
        -v "${MOUNT_DIR}":/mountdir \
        ubuntu:24.04 bash

    echo "Running initialization steps..."
    docker exec -i "${CONTAINER_NAME}" bash <<'EOF'
set -eux
export DEBIAN_FRONTEND=noninteractive
apt update;
apt full-upgrade -y;
apt install tzdata;
ln -fs /usr/share/zoneinfo/Europe/Oslo /etc/localtime
echo "Europe/Oslo" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata;
apt install screen screenie nano vim sudo wget curl htop php-cli python3 python-is-python3 python3-venv git build-essential cmake python3-dev -y;
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb;
dpkg -i cuda-keyring_1.1-1_all.deb;
apt update;
apt -y install cuda-toolkit-12-9;
apt -y install cudnn;
wget 'https://raw.githubusercontent.com/divinity76/bashrc/refs/heads/master/install.sh' -O- | bash
echo 'export PATH="/usr/local/cuda-12.9/bin:$PATH"' >> ~/.bashrc;
echo 'export LD_LIBRARY_PATH="/usr/local/cuda-12.9/lib64:$LD_LIBRARY_PATH"' >> ~/.bashrc;
echo 'export CUDA_HOME="/usr/local/cuda-12.9"' >> ~/.bashrc;
mkdir -p /root/.local/venv;
python3 -m venv /root/.local/venv;
#source ~/.bashrc;
source /root/.local/venv/bin/activate;
pip install --upgrade pip;
#pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128 --upgrade;
#cat /root/.bashrc > /home/ubuntu/.bashrc;
#cat /root/.hansrc > /home/ubuntu/.hansrc;
#cat /root/.bash_aliases > /home/ubuntu/.bash_aliases;
cd /mountdir/training/U-2-Net;
sed 's/=.*//' requirements.txt > requirements.tmp
mv requirements.tmp requirements.txt
pip install -r requirements.txt;
EOF
    docker exec -it "${CONTAINER_NAME}" bash
fi

```

i run

```auto
bash docker.sh 

```

every time i want to access the docker container.

but it includes stuff like

```auto
wget 'https://raw.githubusercontent.com/divinity76/bashrc/refs/heads/master/install.sh' -O- | bash

```

which you probably don’t want (it’s my personal bash init script, configuring bash to my personal preferences),  
and that script adds to .bashrc stuff like

```auto
if [[! "$PATH" =~ "$HOME/.local/bin"]]; then
    if [[-d "$HOME/.local/bin"]]; then
        export PATH="$HOME/.local/bin:$PATH"
    fi
fi
# activate virtualenv if it exists and isn't already activated
if [[-z "$VIRTUAL_ENV"]]; then
    if [[-f "$HOME/.local/venv/bin/activate"]]; then
        VIRTUAL_ENV_DISABLE_PROMPT=1 source "$HOME/.local/venv/bin/activate"
    fi
fi

```

which might be relevant to getting it to work.
