在 Ubuntu 22.04 上安装 NVIDIA 驱动程序时出错

在 Ubuntu 22.04 上安装 NVIDIA 驱动程序时出错

我正在尝试在 Ubuntu 22.04 上安装 CUDA 12.1。我的笔记本电脑配备 2060。

这些是我使用过的命令。第一个命令是卸载我当前的 cuda 驱动程序,第二个命令是安装 CUDA 12.1(这些命令来自):

sudo apt-get --purge remove "*cublas*" "*cufft*" "*curand*" "*cusolver*" "*cusparse*" "*npp*" "*nvjpeg*" "cuda*" "nsight*"
sudo apt-get --purge remove "*nvidia*"
sudo apt-get autoremove

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda-repo-ubuntu2204-12-1-local_12.1.0-530.30.02-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-1-local_12.1.0-530.30.02-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-1-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

使用最后一个命令时我收到以下错误:

dpkg: dependency issues prevent configuration of cuda-drivers-530:
  cuda-drivers-530 depends on nvidia-dkms-530 (>= 530.30.02); however:
  The `nvidia-dkms-530' package is not configured yet.

dpkg: error processing package cuda-drivers-530 (--configure):
  dependency issues - left unconfigured
Configuring libxml2:i386 (2.9.13+dfsg-1ubuntu0.4) ...
An "apport" report was not written because the error message indicates that it is an error message associated with a previous failure.
                                            Configuring cuda-compiler-12-1 (12.1.0-1)...
Configuring libxcb-dri3-0:i386 (1.14-3ubuntu3) ...
Configuring libx11-xcb1:i386 (2:1.7.5-1ubuntu0.3) ...
Configuring cuda-libraries-12-1 (12.1.0-1)...
Configuring libnvjitlink-dev-12-1 (12.1.55-1)...
Configuring libgbm1:i386 (23.2.1-1ubuntu3.1~22.04.2) ...
Configuring libcusparse-dev-12-1 (12.0.2.55-1)...
Configuring libcurand-dev-12-1 (10.3.2.56-1)...
Configuring libxext6:i386 (2:1.3.4-1build1) ...
dpkg: dependency issues prevent nvidia-driver-530 from being configured:
  nvidia-driver-530 depends on nvidia-dkms-530 (=530.30.02-0ubuntu1); however:
  The `nvidia-dkms-530' package is not configured yet.

dpkg: error processing package nvidia-driver-530 (--configure):
  dependency issues - left unconfigured
An "apport" report was not written because the error message indicates that it is an error message associated with a previous failure.
                                            Configuring libcublas-dev-12-1 (12.1.0.26-1)...
Configuring libxxf86vm1:i386 (1:1.1.4-1build3) ...
Configuring libegl-mesa0:i386 (23.2.1-1ubuntu3.1~22.04.2) ...
Configuring libxfixes3:i386 (1:6.0.0-1) ...
dpkg: dependency issues prevent configuration of cuda-drivers:
  cuda-drivers depends on cuda-drivers-530 (=530.30.02-1); however:
  The `cuda-drivers-530' package is not configured yet.

dpkg: error processing package cuda-drivers (--configure):
  dependency issues - left unconfigured
No "apport" report was written because the value of "MaxReports" has already been reached
          Configuring libnvidia-decode-530:i386 (530.30.02-0ubuntu1) ...
Configuring cuda-opencl-dev-12-1 (12.1.56-1)...
Configuring libllvm15:i386 (1:15.0.7-0ubuntu0.22.04.3) ...
Configuring libegl1:i386 (1.4.0-1) ...
Configuring cuda-libraries-dev-12-1 (12.1.0-1)...
Configuring libnvidia-encode-530:i386 (530.30.02-0ubuntu1) ...
dpkg: dependency issues prevent configuration of cuda-runtime-12-1:
  cuda-runtime-12-1 depends on cuda-drivers (>= 530.30.02); however:
  The `cuda-drivers' package is not configured yet.

dpkg: error processing package cuda-runtime-12-1 (--configure):
  dependency issues - left unconfigured
Configuring libgl1-mesa-dri:i386 (23.2.1-1ubuntu3.1~22.04.2) ...
No "apport" report was written because the value of "MaxReports" has already been reached
          Configuring cuda-visual-tools-12-1 (12.1.0-1)...
dpkg: dependency issues prevent configuration of cuda-12-1:
  cuda-12-1 depends on cuda-runtime-12-1 (>= 12.1.0); however:
  Package `cuda-runtime-12-1' is not configured yet.

dpkg: error processing package cuda-12-1 (--configure):
  dependency issues - left unconfigured
Configuring libglx-mesa0:i386 (23.2.1-1ubuntu3.1~22.04.2) ...
No "apport" report was written because the value of "MaxReports" has already been reached
          Configuring libglx0:i386 (1.4.0-1) ...
dpkg: dependency issues prevent cuda configuration:
  cuda depends on cuda-12-1 (>= 12.1.0); however:
  Package `cuda-12-1' is not configured yet.

dpkg: error processing cuda package (--configure):
  dependency issues - left unconfigured
dpkg: dependency issues prevent configuration of cuda-demo-suite-12-1:
  cuda-demo-suite-12-1 depends on cuda-runtime-12-1; however:
  Package `cuda-runtime-12-1' is not configured yet.

dpkg: error processing package cuda-demo-suite-12-1 (--configure):
  dependency issues - left unconfigured
Configuring cuda-tools-12-1 (12.1.0-1)...
No "apport" report was written because the value of "MaxReports" has already been reached
          No "apport" report was written because the value of "MaxReports" has already been reached
                   Configuring cuda-toolkit-12-1 (12.1.0-1)...
Configuring libgl1:i386 (1.4.0-1) ...
Configuring libnvidia-gl-530:i386 (530.30.02-0ubuntu1) ...
Configuring libnvidia-fbc1-530:i386 (530.30.02-0ubuntu1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.6)...
Processing triggers for man-db (2.10.2-1)...
Processing triggers for dbus (1.12.20-2ubuntu4.1)...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3)...
Processing triggers for gnome-menus (3.36.0-1ubuntu3)...
Processing even triggers to initramfs-tools (0.140ubuntu13.4)...
update-initramfs: Generating /boot/initrd.img-6.5.0-27-generic
Errors found when processing:
  nvidia-dkms-530
  cuda-drivers-530
  nvidia-driver-530
  cuda drivers
  cuda-runtime-12-1
  cuda-12-1
  cuda
  cuda-demo-suite-12-1
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

最后我找到了一个安装指南,我可以成功安装它。这是指导

答案2

你試過sudo apt --fix-broken install嗎?

如果上述命令没有帮助,请尝试使用命令再次卸载:

sudo apt-get purge nvidia*
sudo apt remove nvidia-*
sudo rm /etc/apt/sources.list.d/cuda*
sudo apt-get autoremove && sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*

并以困难的方式安装它。它可能不是您的完整指南,但它一定能为您提供有关安装过程中可能出现问题的多种原因和步骤的帮助。

安装依赖项:

sudo apt-get install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev

检查 gcc 编译器版本:

gcc --version

并安装相应的 Bazel 版本(检查版本兼容性这里):

sudo apt install apt-transport-https curl gnupg
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg
sudo mv bazel-archive-keyring.gpg /usr/share/keyrings
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc
/apt/sources.list.d/bazel.list
sudo apt update
sudo apt install bazel-***YOUR-VERSION***
sudo ln -s /usr/bin/bazel-1.0.0 /usr/bin/bazel

下载兼容的 CUDA 版本(从上面的链接检查版本):

wget https://developer.download.nvidia.com/compute/cuda/YOUR-VERSION/local_installers/cuda_***YOUR-VERSION***_linux.run

运行安装程序来安装 CUDA 驱动程序:

sudo sh cuda_***YOUR-VERSION***_linux.run

工具的设置路径:

echo 'export PATH=/usr/local/cuda-***YOUR-VERSION***/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-***YOUR-VERSION***/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig

从 Nvidia 网站下载 CuDNN(从上面的链接检查版本): https://developer.nvidia.com/compute/machine-learning/cudnn/secure/***YOUR-VERSION***/***YOUR-VERSION***/cudnn-***YOUR-VERSION***-linux-x64-***YOUR-VERSION***.tgz

tar -xzvf cudnn-***YOUR-VERSION***-linux-x64-***YOUR-VERSION***.tgz

将 CuDNN 文件复制到 Nvidia 工具包目录(路径可能有所不同):

sudo cp -P cuda/include/cudnn*.h /usr/local/cuda-***YOUR-VERSION***/include
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-***YOUR-VERSION***/lib64/
sudo chmod a+r /usr/local/cuda-***YOUR-VERSION***/lib64/libcudnn*

为 CuDNN 添加 PATH(路径可能有所不同):

sudo nano /home/username/.bashrc
Insert in the end of the config file the row:
export PATH="/usr/local/cuda-***YOUR-VERSION***/bin:$PATH"

然后重启 PC。重启后输入nvidia-smi命令,您应该会看到驱动程序信息和已安装的 CUDA 版本。

如果 Nvidia-installer.log 中的 Nvidia 日志出现错误 检查 /var/log/nvidia-installer.log 或 /var/log/cuda-installer.log 中的日志 在此处输入图片描述 通常,错误和屏幕截图会导致 Nouveau 内核驱动程序。要绕过错误,您需要执行以下步骤:

  1. 再次按照第一步清除 nvidia

  2. WaylandEnable=false取消注释/etc/gdm3/custom.conf

  3. 使用命令创建文件:sudo nano /etc/modprobe.d/blacklist-nouveau.conf并添加行:

    新黑名单

    选项 nouveau modeset=0

  4. 使用 ctrl+O 组合键保存

  5. 运行命令以应用更改:sudo update-initramfs -u

  6. 重启电脑

  7. 重复步骤Run installer to install CUDA drivers

如果错误再次出现在日志中:

  1. 在 Ubuntu 恢复菜单中启动(PC 启动后立即点击 ESC)

  2. root 下进入终端

  3. 执行步骤Run installer to install CUDA drivers

  4. 重新引导至正常界面

  5. 执行其余步骤以完成所有设置

相关内容