ubuntu18.04安装显卡驱动及CUDA的安装-Linux

一、电脑配置

双系统

显卡:RTX2060

二、确定显卡驱动的安装版本

ubuntu-drivers devices

输入后出现如下提示:

cmn@cmn-ubuntu:~/ROS_ws/yin_ws$ ubuntu-drivers devices
WARNING:root:_pkg_get_support nvidia-driver-515: package has invalid Support PBheader, cannot determine support level
WARNING:root:_pkg_get_support nvidia-driver-510-server: package has invalid Support PBheader, cannot determine support level
WARNING:root:_pkg_get_support nvidia-driver-510: package has invalid Support PBheader, cannot determine support level
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001F06sv00007377sd00000000bc03sc00i00
vendor   : NVIDIA Corporation
driver   : nvidia-driver-515 - third-party non-free
driver   : nvidia-driver-450-server - distro non-free
driver   : nvidia-driver-510-server - distro non-free
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-510 - distro non-free
driver   : nvidia-driver-470 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

虽然有警告,但是提示我可以装510

三、安装驱动

sudo apt-get update
sudo apt-get install nvidia-driver-510-server

如果出现如下报错:

W: Possible missing firmware /lib/firmware/rtl_nic/rtl8125a-3.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168fp-3.fw for module r8169

参考:

W: Possible missing firmware /lib/firmware/rtl_nic/rtl8125a-3.fw for module r8169_TwilightZrui的博客-CSDN博客

问题定位:

缺少固件,需要手动补充,解决方法:

1.进入如下地址:

rtl_nic - kernel/git/firmware/linux-firmware.git - Repository of firmware blobs for use with the Linux kernel

2.根据报错,从如上网址中下载缺少的固件

cd /lib/firmware/rtl_nic/
sudo wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/rtl_nic/rtl8125a-3.fw
sudo wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/rtl_nic/rtl8168fp-3.fw

3.再次查看

sudo update-initramfs -u

接下来继续安装:

sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev

重启检查是否安装成功(确保BIOS中secure boot设置为disabled):

nvidia-smi

出现如下提示即安装成功:

cmn@cmn-ubuntu:~$ nvidia-smi
Fri Jun 24 15:31:11 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.73.08    Driver Version: 510.73.08    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:01:00.0  On |                  N/A |
| 60%   49C    P8    24W / 184W |    320MiB /  8192MiB |      1%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1494      G   /usr/lib/xorg/Xorg                 24MiB |
|    0   N/A  N/A      1554      G   /usr/bin/gnome-shell               49MiB |
|    0   N/A  N/A      1738      G   /usr/lib/xorg/Xorg                160MiB |
|    0   N/A  N/A      1863      G   /usr/bin/gnome-shell               83MiB |
+-----------------------------------------------------------------------------+

四、CUDA安装

官网连接:CUDA Toolkit Archive | NVIDIA Developer

我选择的是cuda-10.0版本,选择runfile格式的cuda文件下载,大概1.9G

然后执行如下命令:

sudo bash cuda_10.0.130_410.48_linux.run

压住回车键,直到服务条款显示到100%。接着按下面的步骤选择:

accept

n(不要安装driver)

y

y

y

安装完成后,输入:nvcc -V

显示如下即安装完成:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

安装完成后,设置环境变量:

打开文件:gedit ~/.bashrc

在文件中添加如下路径:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64
export PATH=$PATH:/usr/local/cuda-10.0/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-10.0

保存运行:

source ~/.bashrc

你可能感兴趣的:(Linux,ubuntu,linux)