Skip to content

cuDNN Error In Ubuntu And WSL

If you are working in more than a single WSL and several virtual environments, you have likely run into issues that seems as if they should have a simple solution.

That’s what happened to me today, and a simple thing like transcribing a couple of hours of audio became a very annoying debugging session. If you found your way here because of a similar error, I hope I can save you some time.

Exactly what caused the error is a bit unclear, but I believe it might have been when I bought a new PC. I had backed up the WSL I was using with my old PC, and restored it in the new one. But as I already had a WSL named Ubuntu-24.04, I re-named the old WSL as I restored it. And everything seemed to work just fine, until today.

The symptoms

In my case I was running a transcription tool that uses ONNX Runtime with GPU support. Instead of transcribing, it failed with a message about a missing library. Naturally I tried to install the missing library, and that’s where it got weird:

(venv) Creepybits:~$ ldconfig -p | grep libcudart
        libcudart.so.13 (libc6,x86-64) => /usr/local/cuda/targets/x86_64-linux/lib/libcudart.so.13
        libcudart.so (libc6,x86-64) => /usr/local/cuda/targets/x86_64-linux/lib/libcudart.so

(venv) Creepybits:~$ sudo apt install cudnn9-cuda-13
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package cudnn9-cuda-13

CUDA itself was clearly installed, since ldconfig found libcudart.so.13. But when I tried to install the matching cuDNN package, apt claimed it didn’t exist.

Why this happens

“Unable to locate package” usually doesn’t mean the package doesn’t exist. It means none of the repositories apt knows about provide it. Ubuntu’s default repositories don’t include cuDNN, so you need NVIDIA’s repository set up first. In a fresh WSL install that is usually already in place from when you installed CUDA. In a restored or copied WSL, though, it’s easy to end up with CUDA files present but the apt source missing.

I can’t say for sure that’s what happened to me, but it fits: a restored backup, a renamed distro, and everything working until the day I needed cuDNN. The fix below works either way, because it adds the repository and its signing key so that apt can find the package again.

What worked for me

After finding and testing way too many solutions I found on internet, this was what eventually worked.

Head over to NVIDIA and select the version (Ubuntu 24.04 in my case) you have installed.

cuDNN error cuda 13

Follow the instructions:

wget https://developer.download.nvidia.com/compute/cudnn/9.27.0/local_installers/cudnn-local-repo-ubuntu2404-9.27.0_1.0-1_amd64.deb
sudo dpkg -i cudnn-local-repo-ubuntu2404-9.27.0_1.0-1_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2404-9.27.0/cudnn-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update

Now you should be able to install cuDNN the regular way in whichever WSL or venv you were getting the error in.

If you are using CUDA 13.x run this next:

sudo apt-get -y install cudnn9-cuda-13

For CUDA 12.x run this instead:

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

Check that it worked

First, confirm apt can now see the package:

apt-cache policy cudnn9-cuda-12

Or if you have CUDA 13.x

apt-cache policy cudnn9-cuda-13

You should see a candidate version rather than (none). After installing, check what’s on the system:

dpkg -l | grep cudnn

If you happened to have onnxruntime and onnxruntime-gpu installed, you will need to re-install them.

pip uninstall onnxruntime onnxruntime-gpu -y
pip install onnxruntime-gpu

Then confirm ONNX Runtime actually sees your GPU:

python -c "import onnxruntime as ort; print(ort.get_available_providers())"

If CUDAExecutionProvider is in the list, you’re done. If it only shows CPUExecutionProvider, something is still off. Check the next section.

A few notes:

  • Which CUDA version do you have? The install command depends on it (-12 or -13). Run nvidia-smi and look at the CUDA version in the top right, or nvcc --version if the toolkit is installed. Note that nvidia-smi shows the highest version your driver supports, not necessarily what’s installed.
  • The driver lives in Windows. In WSL you don’t install an NVIDIA driver inside Linux. The Windows driver is shared with WSL, so keep that one up to date.
  • Why reinstall onnxruntime? Having both onnxruntime and onnxruntime-gpu installed side by side can cause the CPU build to shadow the GPU one. Uninstalling both and reinstalling onnxruntime-gpu gives you a clean state.
  • Virtual environments. cuDNN is installed system-wide with apt, but the pip packages live inside each venv. If you have several, you’ll need to do the reinstall step in every one that uses onnxruntime.
  • The version number will change. The download link above is for cuDNN 9.27.0. NVIDIA releases new versions regularly, so use their download page to generate the current commands for your distro rather than copying mine blindly.

Wrapping up
This cost me a few hours that should have been ten minutes, mostly because the advice I found online was for different problems with similar-looking error messages. If it saved you some time, great. If you found something else that worked for you, I’d like to hear about it.

Don’t forget to sign up on our weekly newsletter, and receive tips and tricks directly in your inbox.

Published inAIEnglishPythonSoftwareTech