如何在 Ubuntu 21.04 上安装 NVIDIA 驱动程序
目标是在 Ubuntu 21.04 Hirsute Hippo Linux 上安装 NVIDIA 驱动程序,并从开源 Nouveau 驱动程序切换到专有 Nvidia 驱动程序。
要在其他 Linux 发行版上安装 Nvidia 驱动程序,请遵循我们的 Nvidia Linux 驱动程序指南。
在本教程中您将学习:
如何使用标准 Ubuntu 存储库执行自动 Nvidia 驱动程序安装
如何使用 PPA 存储库执行 Nvidia 驱动程序安装
如何安装 Nvidia.com 官方驱动程序
如何卸载/从 Nvidia 切换回 Nouveau 开源驱动程序
在 Ubuntu 21.04 Hirsute Hippo Linux 上安装了 NVIDIA 驱动程序。安装后,可选择按照我们的 Linux 上的显卡基准测试指南运行 Nvidia 显卡测试。
如何使用标准 Ubuntu 存储库分步说明安装 Nvidia 驱动程序
第一种方法最容易执行,并且在大多数情况下是推荐的方法。
GNOME GUI Nvidia安装方法
打开软件和更新
应用程序窗口。选择 TAB Additional Drivers
并选择任何专有的 NVIDIA 驱动程序。驱动程序编号越高,版本越新。
从 GUI 更新 NVIDIA 驱动程序。
命令行Nvidia安装方法
首先,检测您的nvidia显卡型号以及推荐的驱动程序。为此,请执行以下命令。请注意,您的输出和推荐的驱动程序很可能会有所不同:
$ ubuntu-drivers devices WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level == /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 == modalias : pci:v000010DEd00001C03sv00001043sd000085ABbc03sc00i00 vendor : NVIDIA Corporation model : GP106 [GeForce GTX 1060 6GB] driver : nvidia-driver-450-server - distro non-free driver : nvidia-driver-460-server - distro non-free driver : nvidia-driver-390 - distro non-free driver : nvidia-driver-450 - distro non-free driver : nvidia-driver-460 - distro non-free recommended driver : nvidia-driver-418-server - distro non-free driver : xserver-xorg-video-nouveau - distro free builtin
警告
WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader,无法确定支持级别
输出表明我们没有安装兼容的 NVIDIA 驱动程序。但我们很快就会解决这个问题。安装驱动程序。如果您同意建议,请随时再次使用 ubuntu-drivers 命令来安装所有推荐的驱动程序:
$ sudo ubuntu-drivers autoinstall
或者,使用 apt 命令有选择地安装所需的驱动程序。例如:
$ sudo apt install nvidia-driver-460
安装完成后,重新启动系统即可完成。
$ sudo reboot
使用 PPA 存储库自动安装来安装 Nvidia Beta 驱动程序
使用
graphics-drivers
PPA 存储库使我们能够在系统不稳定的情况下安装最先进的 Nvidia Beta 驱动程序。首先将ppa:graphics-drivers/ppa
存储库添加到您的系统中:$ sudo add-apt-repository ppa:graphics-drivers/ppa
接下来,确定您的显卡型号和推荐的驱动程序:
$ ubuntu-drivers devices WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level == /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 == modalias : pci:v000010DEd00001C03sv00001043sd000085ABbc03sc00i00 vendor : NVIDIA Corporation model : GP106 [GeForce GTX 1060 6GB] driver : nvidia-driver-450-server - distro non-free driver : nvidia-driver-418-server - distro non-free driver : nvidia-driver-450 - distro non-free driver : nvidia-driver-460 - distro non-free recommended driver : nvidia-driver-390 - distro non-free driver : nvidia-driver-460-server - distro non-free driver : xserver-xorg-video-nouveau - distro free builtin
安装 Nvidia 驱动程序与上述标准 Ubuntu 存储库示例相同,要么自动安装所有推荐的驱动程序:
$ sudo ubuntu-drivers autoinstall
或者有选择地使用 apt 命令。例子:
$ sudo apt install nvidia-driver-460
一切完成。重新启动计算机:
$ sudo reboot
使用官方 Nvidia.com 驱动程序分步说明进行手动安装
识别您的 NVIDIA VGA 卡。以下命令将允许您识别您的 Nvidia 卡型号:
$ lshw -numeric -C display or $ lspci -vnn | grep VGA or $ ubuntu-drivers devices
下载官方 Nvidia 驱动程序。使用 Web 浏览器导航到 Nvidia 官方网站并下载适合您的 Nvidia 显卡的驱动程序。或者,如果您知道自己在做什么,则可以直接从 Nvidia Linux 驱动程序列表下载驱动程序。准备好后,您应该会得到一个类似于下图所示的文件:
$ ls NVIDIA-Linux-x86_64-460.67.run
安装先决条件。编译和安装 Nvidia 驱动程序需要满足以下先决条件:
$ sudo apt install build-essential libglvnd-dev pkg-config
禁用 Nouveau Nvidia 驱动程序。下一步是禁用默认的 nouveau Nvidia 驱动程序。请按照本指南了解如何禁用默认的 Nouveau Nvidia 驱动程序。
警告
根据您的 Nvidia VGA 型号,您的系统可能会出现问题。在此阶段,请准备好亲自动手。重新启动后,您可能根本就没有 GUI。确保您的系统上启用了 SSH,以便能够远程登录或使用 CTRL+ALT+F2 切换 TTY 控制台并继续安装。停止桌面管理器。为了安装新的 Nvidia 驱动程序,我们需要停止当前的显示服务器。最简单的方法是使用 telinit 命令更改为运行级别 3。执行以下 linux 命令后,显示服务器将停止,因此请确保在继续之前保存所有当前工作(如果有):
$ sudo telinit 3
安装 Nvidia 驱动程序。要开始安装 Nvidia 驱动程序,请执行以下 linux 命令并按照向导操作:
$ sudo bash NVIDIA-Linux-x86_64-460.67.run OR $ sudo bash NVIDIA-Linux-x86_64-*.run
Nvidia 驱动程序现已安装。重新启动系统:
$ sudo reboot
配置 NVIDIA X 服务器设置。重新启动后,您应该能够从“活动”菜单启动 NVIDIA X 服务器设置应用程序。
如何卸载 Nvidia 驱动程序
请按照我们的指南了解如何卸载 Nvidia 驱动程序,从而从 Nvidia 切换回 Nouveau 开源驱动程序。
附录
错误信息:
WARNING: Unable to find suitable destination to install 32-bit compatibility libraries
根据您的需要,可以安全地忽略这一点。不过,如果你想安装steam游戏平台,这个问题就不能忽视。要解决执行:
$ sudo dpkg --add-architecture i386
$ sudo apt update
$ sudo apt install libc6:i386
并重新运行 nvidia 驱动程序安装。
An incomplete installation of libglvnd was found. All of the essential libglvnd libraries are present, but one or more optional
components are missing. Do you want to install a full copy of libglvnd? This will overwrite any existing libglvnd libraries.
您缺少 libglvnd-dev
软件包。执行以下命令来解决此问题:
$ sudo apt install libglvnd-dev
Oct 9 10:36:20 linuxconfig gdm-password]: gkr-pam: unable to locate daemon control file
Oct 9 10:36:20 linuxconfig gdm-password]: pam_unix(gdm-password:session): session opened for user linuxconfig by (uid=0)
Oct 9 10:36:20 linuxconfig systemd-logind[725]: New session 8 of user linuxconfig.
Oct 9 10:36:20 linuxconfig systemd: pam_unix(systemd-user:session): session opened for user linuxconfig by (uid=0)
Oct 9 10:36:21 linuxconfig gdm-password]: pam_unix(gdm-password:session): session closed for user linuxconfig
Oct 9 10:36:21 linuxconfig systemd-logind[725]: Session 8 logged out. Waiting for processes to exit.
Oct 9 10:36:21 linuxconfig systemd-logind[725]: Removed session 8.
Oct 9 10:36:45 linuxconfig dbus-daemon[728]: [system] Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)
要解决此问题,请在 Nvidia 驱动程序安装期间不要覆盖任何现有的 libglvnd 库。
WARNING: Unable to determine the path to install the libglvnd EGL vendor library config files. Check that you have pkg-config and
the libglvnd development libraries installed, or specify a path with --glvnd-egl-config-path.
确保安装 pkg-config
包:
$ sudo apt install pkg-config