> ## Content Index
> Fetch the complete content index at: https://yinguobing.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# 修复NVIDIA驱动与库版本冲突
- URL: https://yinguobing.com/blog/fix-nvidia-driver-library-mismatch/
- Published: 2021-06-07T06:03:27.000Z
- Updated: 2021-06-07T06:13:40.000Z
- Description: GPU驱动安装要小心谨慎
- Author: 尹国冰
- Tags: Linux

使用\`nvidia-smi\`时系统报错：

```bash
Failed to initialize NVML: Driver/library version mismatch
```

[官方的解释](https://forums.developer.nvidia.com/t/failed-to-initialize-nvml-driver-library-version-mismatch/50910?ref=yinguobing.com)如下：

> the driver was not installed correctly. This can happen if the previous driver was installed using the runfile installer and the new driver was installed using package manager, or vice versa. There are probably other scenarios as well.  
> Remove all previous package manager installs, and all previous runfile installer installs, then reinstall the driver.

简单的说就是使用了两种不同的方式安装或更新了驱动，导致版本冲突。这种情况下最好卸载之前安装的全部显卡驱动，然后重新安装。

---

### 第一步，卸载现有驱动。

如果驱动是使用包管理器安装的（ `apt` 命令），可以再次使用 `apt` 命令将其删除。如果是使用 `.run` 文件离线安装的，则再次使用该文件并附加 `--uninstall` 参数卸载。如果 `.run` 包不可用，可以手动移除。这里有一篇文章可以参考：

[解决Driver/library version mismatch | Comzyh的博客服务器更新nvidia driver 版本之后，经常会出现 \[crayon-5f393399410e1210020202/\] 这个问题出现的原因是kernel mod 的 Nvidia driver 的版本没有更新，一般情况下，重启机器就能够解决，如果因为某些原因不能够重启的话，也有办法reload kernel mod。 简单来看，就两步 unload nvidia kernel mod relComzyh的博客comzyh![](https://comzyh.com/blog/wp-content/plugins/all-in-one-seo-pack/images/default-user-image.png)](https://comzyh.com/blog/archives/967/?ref=yinguobing.com)

如果你无法删除 `nvidia_drm` 模块，有可能是因为安装了图形界面。此时需要按照[这个指南](https://unix.stackexchange.com/questions/440840/how-to-unload-kernel-module-nvidia-drm?ref=yinguobing.com)执行该命令禁用图形对象：

```bash
# systemctl isolate multi-user.target
```

之后再依次删除其它相关项目。

这一步完成后全部驱动相关文件移除完毕。

### 第二步，安装新驱动

按照实际情况选择安装方式。如果没有特殊原因的话，使用系统自带的包管理器即可。例如在Ubuntu下：

```bash
sudo apt install nvidia-driver-460
```

安装完成后即可使用 `nvidia-smi` 命令查阅GPU信息。

### 第三步，安装NVIDIA-DOCKER2（可选）

这一步是可选项。遵循官方安装指南即可。

[Installation Guide — NVIDIA Cloud Native Technologies documentation![](https://docs.nvidia.com/datacenter/cloud-native/_static/nvidia.ico)![](https://docs.nvidia.com/datacenter/cloud-native/_static/NVLogo_H_B&W.png)](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html?ref=yinguobing.com#docker)