Install Nvidia drivers + CUDA on Debian 12 (bookworm) + nvidia-smi + ollama and Docker

When I set out to install NVIDIA drivers alongside CUDA on my machine, I often find myself grappling with frustrating version mismatches that complicate the entire process. One of the most critical tools in this ecosystem is nvidia-smi, which provides vital insights into GPU processes and resource consumption. However, I frequently encounter a common issue: the version of nvidia-smi tends to lag behind the latest NVIDIA drivers. For example, as of April 2025, I might be working with driver version 570 while nvidia-smi is still at version 560. This discrepancy can lead to significant problems, as blindly installing the latest drivers without ensuring compatibility can render nvidia-smi inoperable. Therefore, I’ve learned the importance of carefully navigating these version dependencies to ensure a smooth installation and optimal performance of my GPU resources.

Press enter or click to view image in full size

Image randomly generated when playing around with https://chat.together.ai/ with FluxSchnell model.

Restrict Debian 12 to install too fresh packages

On the latest Debian (12 — Bookworm), the standard NVIDIA drivers typically install only up to version 535. However, when I install the cuda-keyring to set up for the CUDA driver later, the official NVIDIA repository gets added to my sources, prompting my system to suggest an update to the latest drivers (currently version 570). While there’s nothing inherently wrong with this, and I can proceed with the installation—including the latest CUDA drivers—my nvidia-smi tool, which is at version 560, will end up being outdated.

To prevent this issue, I need to configure my system to avoid installing certain packages with version numbers higher than 560. After experimenting with the various packages involved in the installation process, I’ve found the necessary steps to ensure a functioning system with the most up-to-date drivers and tools.

Create a policy for all nvidia-related drivers

You can name this file however you want, then put these rules into it:

As you can see, I’ve restricted all packages containing the “nvidia” string to a maximum version of 560.35.05–1. I’ve applied the same approach to the other relevant packages, but in this case, I know that these packages start with specific strings, so there’s no need to use wildcards for the first character(s).

We need to run apt update to get the policy in effect.

Install Nvidia drivers and tools

You’ll notice that the appropriate versions are selected and installed. This process may take some time, and you will need to reboot your machine afterward.

Install Cuda drivers

The installation process should go smoothly. Once everything is complete, reboot your machine and enjoy!

+1 extra — Want nvidia and CUDA in Docker?

Luckily, this does not depend much on our hacks above. Just install the Nvidia Container Toolkit and test docker’s access to the GPU.

Next, we need to specify the Nvidia runtime for Docker. We need to add the following extra definitions to docker’s daemon.json (note, the file might not exist, so just create it):

Then, add the following lines:

Then, save and restart docker.

Now test a simple cuda container and nvidia-smi command inside:

If you see the same as above, you are good to go 🙂

Ollama container with WebUI

Here, I just provide you a docker-compose.yml file that does the job for you 🙂

Author: admin

Laisser un commentaire