> ## 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.

# CentOS 7安装Nvidia驱动
- URL: https://yinguobing.com/blog/install-nvidia-driver-centos-7/
- Published: 2022-02-23T05:41:49.000Z
- Updated: 2022-02-23T05:41:49.000Z
- Description: 使用runfile的方式安装NVIDIA驱动
- Author: 尹国冰
- Tags: 新手入门, Linux

本文记录了CentOS 7下以 `runfile` 形式安装Nvidia驱动的过程。

### 准备工作

明确操作系统信息。

```bash
cat /proc/version 
Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020

```

明确显卡硬件信息。

```bash
/sbin/lshw -c display
  *-display                 
       description: VGA compatible controller
       product: GM200 [GeForce GTX 980 Ti]
       vendor: NVIDIA Corporation
       physical id: 0
       bus info: pci@0000:04:00.0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
       configuration: driver=nouveau latency=0
       resources: iomemory:3bf0-3bef iomemory:3bf0-3bef irq:64 memory:91000000-91ffffff memory:3bfe0000000-3bfefffffff memory:3bff0000000-3bff1ffffff ioport:2000(size=128) memory:92080000-920fffff
```

### 下载驱动

访问下方Nvidia官方驱动下载网站，按照实际的硬件规格获取最新驱动版本。

[Download the latest official NVIDIA driversDownload the latest official NVIDIA drivers![](https://www.nvidia.com/favicon.ico)Subscribe![](https://www.nvidia.com/content/dam/en-zz/Solutions/geforce/drivers/cut-graphics/nvidia-geforce-drivers-meta-image-1200x627.jpg)](https://www.nvidia.com/Download/index.aspx?ref=yinguobing.com)

最终会获得驱动版本与下载按钮。

![](https://yinguobing.com/blog/content/images/2022/02/nvidia-driver-download.jpg)

驱动下载页面

点击下载即可获得驱动文件的地址。示例中的地址如下：

```shell
https://us.download.nvidia.com/XFree86/Linux-x86_64/510.54/NVIDIA-Linux-x86_64-510.54.run
```

获得下载地址后，使用curl将文件下载到本地。

```bash
curl -SL https://us.download.nvidia.com/XFree86/Linux-x86_64/510.54/NVIDIA-Linux-x86_64-510.54.run -O
```

### 安装驱动

💡

以下操作均以root用户身份执行。

#### 禁用旧驱动

在终端中执行：

```bash
sh NVIDIA-Linux-x86_64-510.54.run
```

此时会提示 `Nouveau` 驱动正在使用中。

![](https://yinguobing.com/blog/content/images/2022/02/Nouveau.jpg)

点击确定后，会弹出建议解决方法。选择Yes，回车。

![](https://yinguobing.com/blog/content/images/2022/02/Nouveau-2.jpg)

此时会弹出提示操作完成，回车确认。

![](https://yinguobing.com/blog/content/images/2022/02/Nouveau-3.jpg)

至此仅仅完成了旧驱动的禁用操作，还未安装新驱动，因此会显示驱动安装失败。没关系，重新启动机器。

#### 启动安装

继续回到中断，再次执行安装指令。

```bash
sh NVIDIA-Linux-x86_64-510.54.run
```

此次可能会报其它错误，例如：

##### 找不到编译器

![](https://yinguobing.com/blog/content/images/2022/02/gcc-not-found.png)

类似的错误可以通过 `yum` 管理器安装缺失的组件即可。

```bash
yum install gcc
```

##### Kernel source files缺失

![](https://yinguobing.com/blog/content/images/2022/02/kernel-source-files-missing.jpg)

安装缺失的包。

```bash
yum install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r)
```

##### 找不到X library path

![](https://yinguobing.com/blog/content/images/2022/02/x-library-path-1.jpg)

![](https://yinguobing.com/blog/content/images/2022/02/x-config.jpg)

对于服务器端来说可以不理会X服务。

##### 启用32位支持

![](https://yinguobing.com/blog/content/images/2022/02/32bit-driver.jpg)

此项视情况，我最后选择的是“No”。

安装到最后最显示安装成功提示。

![](https://yinguobing.com/blog/content/images/2022/02/final-note.jpg)

#### 验证安装结果

使用 `nvidia-smi` 命令验证：

```bash
nvidia-smi 
Wed Feb 23 11:47:34 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.54       Driver Version: 510.54       CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:04:00.0 Off |                  N/A |
| 18%   28C    P0    62W / 250W |      0MiB /  6144MiB |      2%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

```

至此安装过程结束。

如果你在安装过程中遇到问题，可以参考官方的安装指南。注意匹配版本。

[NVIDIA Accelerated Linux Graphics Driver README andInstallation GuideNVIDIACorporation](https://download.nvidia.com/XFree86/Linux-x86%5F64/510.54/README/?ref=yinguobing.com)