AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1077061
Accepted
Terrance
Terrance
Asked: 2018-09-21 14:11:25 +0800 CST2018-09-21 14:11:25 +0800 CST 2018-09-21 14:11:25 +0800 CST

如何在 Ubuntu 中安装 NVIDIA 和 CUDA 驱动程序?

  • 772

编辑:我在下面为 Ubuntu 20.04 LTS 和 CUDA 11.1.1 添加了一个新答案。见下文。


我有一个带有 NVIDIA 卡的系统,与https://developer.nvidia.com/cuda-gpus相比,它的计算支持为 3.5+ 。如何在不从 NVIDIA 下载 .deb 文件的情况下在 Ubuntu 中安装 CUDA 和 NVIDIA 驱动程序?

nvidia cuda
  • 5 5 个回答
  • 134292 Views

5 个回答

  • Voted
  1. Terrance
    2018-09-21T14:13:21+08:002018-09-21T14:13:21+08:00

    Ubuntu 18.04、CUDA 10.1、libcudnn 7.5.1 和 NVIDIA 418.67 驱动程序


    笔记

    • 2021-01-07 : 请继续使用下面的 20.04 安装,因为 18.04 和 20.04 的步骤相同。

    • 2019-06-23 : CUDA 10.0 或 10.1 版本的最新更新与它一起安装的 NVIDIA 418.67 驱动程序不再包含 32 位库,这将导致 Steam 和大多数游戏不再工作。的版本libnvidia-gl-418:i386只安装 418.56 版本,不支持 418.67 驱动。希望 NVIDIA 将很快发布更新。我已在此答案底部添加了.run file install有关如何仅下载 CUDA 安装程序的运行文件的信息,然后您可以使用所需的任何驱动程序。 运行文件大小为 2.3GB,因此下载可能需要一些时间。

    • CUDA 9.x 无法通过 NVIDIA 的 ubuntu1804 存储库获得。但是,我确实在https://askubuntu.com/a/1086993/231142上为 CUDA 9.2 写了一个答案


    通过存储库安装 CUDA(而不是.deb安装)

    您可以将以下行复制并粘贴到终端窗口。按Ctrl+ Alt+T打开终端窗口。

    删除和更新

    删除任何可能已安装的 CUDA PPA,并删除nvidia-cuda-toolkit如果已安装:

    sudo rm /etc/apt/sources.list.d/cuda*
    sudo apt remove --autoremove nvidia-cuda-toolkit
    

    建议在安装新驱动程序之前也删除所有 NVIDIA 驱动程序:

    sudo apt remove --autoremove nvidia-*
    

    然后更新系统:

    sudo apt update
    

    添加并安装

    最近,我刚刚发现 CUDA 安装可以使用,graphics-drivers ppa所以如果你没有添加它,现在添加它:

    sudo add-apt-repository ppa:graphics-drivers/ppa
    sudo apt update
    

    安装 NVIDIA 驱动程序。为此,我们将使用 440 驱动程序

    sudo apt install nvidia-driver-440
    

    现在,安装密钥:

    sudo apt-key adv --fetch-keys  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
    

    添加回购:

    sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
    
    sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda_learn.list'
    

    再次更新系统:

    sudo apt update
    

    安装 CUDA 10.1:

    sudo apt install cuda-10-1
    

    它应该与它一起安装 NVIDIA 418.40 驱动程序,因为这些驱动程序在 repo 中列出。请参阅:http: //developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/

    安装 libcudnn7 7.5.1:

    sudo apt install libcudnn7
    

    调整环境并重新启动

    将以下行添加到~/.profileCUDA 10.1 的文件中

    # set PATH for cuda 10.1 installation
    if [ -d "/usr/local/cuda-10.1/bin/" ]; then
        export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
        export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    fi
    

    重新启动计算机。

    检查您的设置

    检查 NVIDIA Cuda 编译器nvcc --version:

    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2019 NVIDIA Corporation
    Built on Wed_Apr_24_19:10:27_PDT_2019
    Cuda compilation tools, release 10.1, V10.1.168
    

    检查 libcudnn 版本/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn:

    terrance@terrance-ubuntu:~$ /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn
        libcudnn.so.7 -> libcudnn.so.7.5.1
    

    检查 NVIDIA 驱动程序nvidia-smi:

    terrance@terrance-ubuntu:~$ nvidia-smi
    Wed Jan 29 12:41:02 2020       
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 440.48.02    Driver Version: 440.48.02    CUDA Version: 10.2     |
    |-------------------------------+----------------------+----------------------+
    | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
    |===============================+======================+======================|
    |   0  GeForce GTX 750 Ti  Off  | 00000000:02:00.0  On |                  N/A |
    | 40%   34C    P0     1W /  38W |    163MiB /  2000MiB |      1%      Default |
    +-------------------------------+----------------------+----------------------+
                                                                                   
    +-----------------------------------------------------------------------------+
    | Processes:                                                       GPU Memory |
    |  GPU       PID   Type   Process name                             Usage      |
    |=============================================================================|
    |    0      1993      G   /usr/lib/xorg/Xorg                           158MiB |
    |    0      2502      G   compton                                        1MiB |
    +-----------------------------------------------------------------------------+
    

    .run文件安装

    安装驱动

    通过使用,sudo add-apt-repository ppa:graphics-drivers/ppa您可以安装430.26最新的驱动程序或任何适合您的驱动程序。

    安装 libcudnn7

    添加回购:

    sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda_learn.list'
    

    安装密钥:

    sudo apt-key adv --fetch-keys  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
    

    更新系统:

    sudo apt update
    

    安装 libcudnn7.5.1:

    sudo apt install libcudnn7
    

    下载.run文件

    现在cuda_10.1.105_418.39_linux.run从https://developer.nvidia.com/cuda-10.1-download-archive-base?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal下载

    如果你想要 CUDA 10.2,下载说明在这里: https ://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal 然后按照以下相同的步骤进行操作,但请确保更新到 10.2 而不是 10.1。

    然后运行安装程序:

    sudo sh cuda_10.1.105_418.39_linux.run
    

    在此屏幕上输入接受并按回车键:

    ┌──────────────────────────────────────────────────────────────────────────────┐
    │  End User License Agreement                                                  │
    │  --------------------------                                                  │
    │                                                                              │
    │                                                                              │
    │  Preface                                                                     │
    │  -------                                                                     │
    │                                                                              │
    │  The Software License Agreement in Chapter 1 and the Supplement              │
    │  in Chapter 2 contain license terms and conditions that govern               │
    │  the use of NVIDIA software. By accepting this agreement, you                │
    │  agree to comply with all the terms and conditions applicable                │
    │  to the product(s) included herein.                                          │
    │                                                                              │
    │                                                                              │
    │  NVIDIA Driver                                                               │
    │                                                                              │
    │                                                                              │
    │  Description                                                                 │
    │                                                                              │
    │  This package contains the operating system driver and                       │
    │──────────────────────────────────────────────────────────────────────────────│
    │ Do you accept the above EULA? (accept/decline/quit):                         │
    │ accept                                                                       
    

    取消选择驱动程序,然后使用箭头键和空格键移动并选择或取消选择选择安装:

    ┌──────────────────────────────────────────────────────────────────────────────┐
    │ CUDA Installer                                                               │
    │ - [ ] Driver                                                                 │
    │      [ ] 418.39                                                              │
    │ + [X] CUDA Toolkit 10.1                                                      │
    │   [X] CUDA Samples 10.1                                                      │
    │   [X] CUDA Demo Suite 10.1                                                   │
    │   [X] CUDA Documentation 10.1                                                │
    │   Install                                                                    │
    │   Options                                                                    │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │ Up/Down: Move | Left/Right: Expand | 'Enter': Select | 'A': Advanced options │
    

    等待安装完成,它可能会在安装过程中出现错误,但不要担心。

    调整环境并重新启动

    将以下行添加到~/.profileCUDA 10.1 的文件中

    # set PATH for cuda 10.1 installation
    if [ -d "/usr/local/cuda-10.1/bin/" ]; then
        export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
        export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    fi
    

    重新启动系统以使更改生效。

    • 89
  2. Best Answer
    Terrance
    2020-10-31T12:53:27+08:002020-10-31T12:53:27+08:00

    Ubuntu 20.04 LTS、CUDA 11.5.0、NVIDIA 495 和 libcudnn 8.0.4


    我不建议安装 CUDA 附带的 NVIDIA 驱动程序,因为它们不包含用于新内核升级的 dkms 驱动程序。

    graphics-driversUbuntu 存储库现在包含与PPA相同的驱动程序。所以请随意安装495.44驱动程序。

    sudo apt install nvidia-driver-495
    

    重新启动系统,使新的驱动程序生效。

    现在,从 NVIDIA 下载 CUDA 11.5.0 .run 文件:

    wget https://developer.download.nvidia.com/compute/cuda/11.5.0/local_installers/cuda_11.5.0_495.29.05_linux.run
    

    .run将文件运行为sudo:

    sudo sh ./cuda_11.5.0_495.29.05_linux.run
    

    如果您得到以下信息,只需选择Continue:

    ┌──────────────────────────────────────────────────────────────────────────────┐
    │ Existing package manager installation of the driver found. It is strongly    │
    │ recommended that you remove this before continuing.                          │
    │ Abort                                                                        │
    │ Continue                                                                     │
    │                                                                             
    

    接受 EULA:

    ┌──────────────────────────────────────────────────────────────────────────────┐
    │  End User License Agreement                                                  │
    │  --------------------------                                                  │
    │                                                                              │
    │  NVIDIA Software License Agreement and CUDA Supplement to                    │
    │  Software License Agreement. Last updated: October 8, 2021                   │
    │                                                                              │
    │  The CUDA Toolkit End User License Agreement applies to the                  │
    │  NVIDIA CUDA Toolkit, the NVIDIA CUDA Samples, the NVIDIA                    │
    │  Display Driver, NVIDIA Nsight tools (Visual Studio Edition),                │
    │  and the associated documentation on CUDA APIs, programming                  │
    │  model and development tools. If you do not agree with the                   │
    │  terms and conditions of the license agreement, then do not                  │
    │  download or use the software.                                               │
    │                                                                              │
    │  Last updated: October 8, 2021.                                              │
    │                                                                              │
    │                                                                              │
    │  Preface                                                                     │
    │  -------                                                                     │
    │                                                                              │
    │──────────────────────────────────────────────────────────────────────────────│
    │ Do you accept the above EULA? (accept/decline/quit):                         │
    │ accept                                                                       
    

    [X] Driver在突出显示时按空格键取消选择视频驱动程序:

    ┌──────────────────────────────────────────────────────────────────────────────┐
    │ CUDA Installer                                                               │
    │ - [ ] Driver                                                                 │
    │      [ ] 495.29.05                                                           │
    │ + [X] CUDA Toolkit 11.5                                                      │
    │   [X] CUDA Samples 11.5                                                      │
    │   [X] CUDA Demo Suite 11.5                                                   │
    │   [X] CUDA Documentation 11.5                                                │
    │   Options                                                                    │
    │   Install                                                                    │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │                                                                              │
    │ Up/Down: Move | Left/Right: Expand | 'Enter': Select | 'A': Advanced options │
    

    然后按向下箭头Install。按Enter然后等待安装完成。

    安装完成后,将以下内容添加到您的底部~/.profile或将其添加到/etc/profile.d/cuda.sh您可能必须为所有用户(全局)创建的文件中:

    # set PATH for cuda 11.5 installation
    if [ -d "/usr/local/cuda-11.5/bin/" ]; then
        export PATH=/usr/local/cuda-11.5/bin${PATH:+:${PATH}}
        export LD_LIBRARY_PATH=/usr/local/cuda-11.5/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    fi
    

    安装 libcudnn8

    添加回购:

    注意:来自 NVIDIA 的 20.04 存储库不提供 libcudnn,但 18.04 存储库提供并可以很好地安装到 20.04 中。

    echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda_learn.list
    

    安装密钥:

    sudo apt-key adv --fetch-keys  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
    

    更新系统:

    sudo apt update
    

    安装 libcudnn 8.0.4:

    sudo apt install libcudnn8
    

    我建议现在重新启动系统以使更改生效。

    重启后检查安装:

    ~$ nvidia-smi
    Thu Nov 18 07:31:31 2021       
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 495.44       Driver Version: 495.44       CUDA Version: 11.5     |
    |-------------------------------+----------------------+----------------------+
    | 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:01:00.0  On |                  N/A |
    | 40%   38C    P8     1W /  38W |    310MiB /  2000MiB |      4%      Default |
    |                               |                      |                  N/A |
    +-------------------------------+----------------------+----------------------+
                                                                                   
    +-----------------------------------------------------------------------------+
    | Processes:                                                                  |
    |  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
    |        ID   ID                                                   Usage      |
    |=============================================================================|
    |    0   N/A  N/A      2091      G   /usr/lib/xorg/Xorg                 46MiB |
    |    0   N/A  N/A      2680      G   /usr/lib/xorg/Xorg                163MiB |
    |    0   N/A  N/A      2906      G   compton                             1MiB |
    |    0   N/A  N/A      3262      G   /opt/waterfox/waterfox             85MiB |
    +-----------------------------------------------------------------------------+
    

    并检查 CUDA 安装:

    ~$ nvcc -V
    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2021 NVIDIA Corporation
    Built on Mon_Sep_13_19:13:29_PDT_2021
    Cuda compilation tools, release 11.5, V11.5.50
    Build cuda_11.5.r11.5/compiler.30411180_0
    

    并检查 libcudnn 安装:

    ~$ /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn
        libcudnn_cnn_infer.so.8 -> libcudnn_cnn_infer.so.8.0.4
        libcudnn.so.8 -> libcudnn.so.8.0.4
        libcudnn_adv_train.so.8 -> libcudnn_adv_train.so.8.0.4
        libcudnn_ops_infer.so.8 -> libcudnn_ops_infer.so.8.0.4
        libcudnn_cnn_train.so.8 -> libcudnn_cnn_train.so.8.0.4
        libcudnn_adv_infer.so.8 -> libcudnn_adv_infer.so.8.0.4
        libcudnn_ops_train.so.8 -> libcudnn_ops_train.so.8.0.4
    
    • 15
  3. Eric Canton
    2021-10-26T09:40:14+08:002021-10-26T09:40:14+08:00

    我只想添加一个替代解决方案,最终变得更容易和模块化,恕我直言:使用 Nvidia 的 CUDA docker 图像!

    这确实需要主机上的工作(专有)驱动程序,可以从 Ubuntu 存储库安装(nvidia-driver-470是 CUDA 计算 3.5 最终支持的驱动程序版本)。

    1. sudo apt install nvidia-driver-470
    2. 安装 Docker 和nvidia-docker2. 请参阅Nvidia 的本指南;如果您运行的是 Ubuntu 21+,您需要在此步骤$distribution中替换为。ubuntu2004
    3. 在Nvidia 的 DockerHub 页面上找到你想要的 CUDA docker 镜像;例如,如果你想要 CUDA 11.4.2 和 cuDNN 8,你可以运行
      $ docker pull nvidia/cuda:11.4.2-cudnn8-devel-ubuntu20.04
      
    4. 现在从该图像运行一个容器,附加您的 GPU:
      $ docker run -it --rm --gpus all nvidia/cuda:11.4.2-cudnn8-devel-ubuntu20.04
      
      您应该验证容器是否可以通过运行来查看您的 GPU nvidia-smi,这将显示您从nvidia-smi在 Docker 中运行 NOT 获得的相同输出。
    • 1
  4. MikeL
    2020-08-03T09:10:57+08:002020-08-03T09:10:57+08:00

    对于使用 AWS 深度学习基础 AMI 的任何人:
    该图像带有几个内置的 NVIDIA CUDA 环境,默认情况下可以使用其中一个(在我的情况下为 10),但您可以切换到任何其他环境,只需更改符号链接:

    $ sudo rm /usr/local/cuda
    $ sudo ln -s /usr/local/cuda-10.2 /usr/local/cuda
    

    更多信息:
    https ://docs.aws.amazon.com/dlami/latest/devguide/tutorial-base.html

    • 0
  5. BarzanHayati
    2019-09-24T21:30:41+08:002019-09-24T21:30:41+08:00

    不要犯错。

    永远下载 .deb 文件。

    我下载了 .run 文件并安装了它。但是,一旦我尝试安装 tensorrt,结果发现它无法安装。

    我只能在安装 .deb nvidia 驱动程序后安装它。

    • -1

相关问题

  • 普利茅斯将来会允许使用专有图形驱动程序获得良好的启动体验吗?

  • 未连接到任何可见进程的令人讨厌的 CPU 峰值

  • 10.04 Lucid 中的多席位状态如何?[关闭]

  • 升级到 10.04 后字体模糊,Nvidia 问题?

  • 帮助让 Flash 播放器在第二个屏幕上工作?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve