How to Fix NVML Errors After a Kernel Update on Ubuntu

Updated on Dec 4, 2026
Mila H
7 MINS READ
Table of Contents
Failed to Initialize NVML

If you run nvidia-smi and get "Failed to initialize NVML: Driver/Library version mismatch", this usually happens after an apt upgrade or a kernel update. This guide shows you how to confirm the cause, fix it safely, and test your GPU workloads.

Why NVML Driver/Library Mismatch Happens

NVML is the NVIDIA Management Library, and nvidia-smi uses it. The error means two parts of the driver have different versions:

  • The kernel module loaded in memory (the old version).
  • The user-space libraries on disk (the new version, installed by apt).

An update replaces the files on disk, but the old module stays loaded until you reboot or reload it. If you use GPU dedicated server hosting, this is a common problem after unattended upgrades.

Now let's check your server step by step to confirm this problem and fix it.

Confirm the Error on the Host

Start on the host, not inside a container. Run nvidia-smi in a normal terminal on the server:

Bash
nvidia-smi
#Example output Failed to initialize NVML: Driver/library version mismatchNVML library version: 5xx.xx

If you see this on the host, it is a host problem, and the next steps will fix it. If it works on the host, the problem is only in your container, so skip to the container section.

Find the NVIDIA Version Mismatch

Now, you must check which driver version is loaded and which one is installed. The error happens when these two are different.

First, check the running kernel and the loaded module version with the commands below:

Bash
uname -rcat /proc/driver/nvidia/version

Then, check the installed driver module version with the commands below:

Bash
modinfo -F version nvidiamodinfo -n nvidia

Next, check for the installed packages with the following commands:

Bash
dpkg -l | grep -i nvidiaapt list --installed 2>/dev/null | grep -Ei 'nvidia-(driver|dkms|utils|kernel)|libnvidia'

Also, check DKMS and held packages with the commands below:

Bash
dkms statusapt-mark showhold

Here is an example of a version mismatch:

$ cat /proc/driver/nvidia/versionNVRM version: NVIDIA UNIX x86_64 Kernel Module  5xx.aaa.bb $ modinfo -F version nvidia5xx.ccc.dd

If the two numbers are different, the old module is still in memory. This is the classic mismatch.

How to Find the Cause of the NVML Error

Use this short checklist to find the cause of your error. Answer each question in order, based on the results you found in the above steps. 

  • nvidia-smi fails on the host. Go to the next question.

  • Does /proc/driver/nvidia/version exist?

    • No: The module is not loaded. Go to "Module Missing After Kernel Update".

    • Yes: Compare it with modinfo -F version nvidia.

  • Are the versions different? Do a planned reboot (Fix A).

  • Are the versions the same, but the error stays after reboot? Check for held packages, mixed driver branches, or a stale initramfs (Fix C).

  • Does the host work, but a container fails? Go to "Container-Only Errors".

Fix A: Planned Reboot (Best Option)

A reboot is the simplest and safest fix. NVIDIA says a reboot will typically resolve this error. First, stop your GPU workloads and then reboot:

Bash
sudo docker pssudo docker stop <container_name>sudo reboot

After the reboot, log in and run nvidia-smi again. If you see the GPU table with your driver version, the fix worked.

Fix B: Reload the Module Without a Reboot

Use this method only if you cannot reboot right now. You can unload the old driver from memory and load the new one. To do this, follow the steps below:

  • Stop everything that uses the GPU:
Bash
sudo docker ps -q | xargs -r sudo docker stopsudo systemctl stop nvidia-persistencedsudo fuser -v /dev/nvidia*
  • Unload the modules:
Bash
sudo modprobe -r nvidia_uvm nvidia_drm nvidia_modeset nvidialsmod | grep nvidia
  • Load the new module and test:
Bash
sudo modprobe nvidianvidia-smi

If a module says "in use", find the process with sudo lsof /dev/nvidia*, stop it, and try again. If it still will not unload, you must reboot.

Fix C: Repair After a Kernel Update

A kernel update can break the NVIDIA driver, because every kernel needs its own matching module. Use these steps if the module is missing, or if the versions still do not match after a reboot.

Module Missing After Kernel Update

A new kernel needs a matching NVIDIA module. With DKMS, the module is rebuilt for the new kernel, and it needs the kernel headers. Check the status with:

Bash
dkms status

A good result looks like this:

nvidia/5xx.xx, 6.8.0-xx-generic, x86_64: installed

If the entry is missing, install the headers and rebuild:

Bash
sudo apt install linux-headers-$(uname -r)sudo dkms autoinstallsudo update-initramfs -usudo reboot

Note: Ubuntu can also use precompiled modules. So if DKMS shows no entry, the module may still be there. Run modinfo -n nvidia to check.

Stale or Mixed Packages

If the versions still differ after a reboot, reinstall the driver package you already use, and do not purge everything:

Bash
sudo apt updatesudo apt install --reinstall nvidia-driver-<branch>sudo reboot

Replace <branch> with your branch from dpkg -l | grep nvidia-driver. Or let Ubuntu pick the recommended driver:

Bash
sudo ubuntu-drivers listsudo ubuntu-drivers install

Secure Boot

If Secure Boot is on, an unsigned module will not load. Run this command to check if Secure Boot is on:

Bash
mokutil --sb-state

If it says enabled, make sure the NVIDIA module is signed, then reboot.

Note: Do not blindly purge drivers. Purging can remove packages you still need and can leave a server without a working GPU stack. First, try the steps above. Use a full reinstall only as a last choice, and use a console or IPMI so you can recover.

Fix NVML Errors Inside Docker Containers

Sometimes nvidia-smi works on the host, but fails inside a Docker container. In this case, the driver is fine, and the problem is in the container setup. Use this step to find the exact error message and fix it.

Run this command to test if a Docker container can use your GPU:

Bash
docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi

Read the exact error message:

  • Driver/library version mismatch: The host is the problem. Fix the host, then restart the container.
  • Unknown Error (the container worked, then lost the GPU): This is a known container issue. A container update can remove GPU access. Delete the container and start it again.

You can run this command to create the missing GPU device links that containers need:

Bash
sudo nvidia-ctk system create-dev-char-symlinks --create-all

Also, you can set Docker to use cgroupfs. Edit /etc/docker/daemon.json with your desired text editor and set:

JSON
{  "exec-opts": [    "native.cgroupdriver=cgroupfs"  ]}

If the file already has other settings, add this line and keep the JSON valid. Then, restart Docker:

Bash
sudo systemctl restart docker

This helps with the daemon-reload case, but not with every container update.

  • Insufficient Permissions: This is usually SELinux on Red Hat systems. It is not common on Ubuntu.

Tips: To set up Docker with GPU access from scratch, you can follow our guide on AI serving with Docker on a dedicated server.

Verify the Fix: Test the Host and Docker

Now make sure the fix really worked. First, check that nvidia-smi works on the host and that the driver versions match:

Bash
nvidia-smicat /proc/driver/nvidia/versionmodinfo -F version nvidia
#Example Output for nvidia-smi: +-----------------------------------------------------------------------------+| NVIDIA-SMI 5xx.xx    Driver Version: 5xx.xx    CUDA Version: 12.x          || GPU  Name              ...   Memory-Usage   GPU-Util                         ||   0  NVIDIA GeForce RTX 4090 ...  1MiB / 24564MiB   0%                       |+-----------------------------------------------------------------------------+

Then, run this command to check that Docker can use your GPU:

Bash
docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi

Next, start your GPU workloads again, for example vLLM or Triton, and check the logs for errors.

Best Practices for NVIDIA Driver Updates

You can avoid this error with a few simple steps. Most cases happen after an update, so plan your updates and reboots. Follow these tips to keep your GPU server stable:

  • Plan a reboot after every driver or kernel update.
  • Do not run driver upgrades during busy hours.
  • Keep one driver source. Do not mix Ubuntu packages and the NVIDIA .run installer.
  • Check dkms status after each kernel update.

If you need a separate machine to test driver updates, you can try a dedicated NVIDIA GPU VPS for smaller jobs.

Conclusion

The failed to initialize NVML error means the loaded driver and the installed libraries have different versions. Compare the two versions, then do a planned reboot. If the error stays, check DKMS, kernel headers, packages, and Secure Boot. If only a container fails, fix the container, not the host. Always finish by running nvidia-smi on the host and in a container.

We hope you enjoy this troubleshooting guide. For more detailed information, you can check the NVIDIA Enterprise Support.