一、安装依赖
1、更新
sudo apt update
sudo apt upgrade -y
2、基础工具
sudo apt install -y build-essential cmake
图形界面相关
sudo apt install -y lightdm
注:在弹出对话框选择"lightdm"
下载nvidia驱动:
进入如下网址:https://www.nvidia.cn/
点击右上角"驱动程序",根据显卡型号需要0选择相应选项:
下载得到:NVIDIA-Linux-x86_64-550.107.02.run驱动文件
安装驱动前的系统配置工作
1、卸载原有驱动
sudo apt remove --purge nvidia*
2、禁用nouveau
备份文件
sudo cp /etc/modprobe.d/blacklist.conf /etc/modprobe.d/blacklist.conf.backup
打开文件
sudo gedit /etc/modprobe.d/blacklist.conf
修改文件
在文件末尾添加如下内容
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
保存后关闭文件
关闭nouveau
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
更新
sudo update-initramfs -u
重启电脑
reboot
重启后查看是否禁用成功
执行以下内容,没有任何输出内容则为成功禁用
lsmod | grep nouveau
开始安装驱动(以下需要进入黑窗口,可以将下面命令拍照或使用手机CSDN查看继续)
(1)按下组合键ctrl+alt+f3(f1-f6均可)进入字符界面
(2)字符界面登陆
注意此时小键盘不可用,先输入用户名,再输入密码
(3)关闭图形界面
sudo service lightdm stop
给驱动文件赋予执行权限
cd /home/heqingchun/soft/nvidia
chmod 755 NVIDIA-Linux-x86_64-535.113.01.run
安装
-no-x-check:安装驱动时关闭X服务 -no-nouveau-check:安装驱动时禁用nouveau -no-opengl-files:只安装驱动文件,不安装OpenGL文件
sudo ./NVIDIA-Linux-x86_64-535.113.01.run -no-x-check -no-nouveau-check
安装过程中一些选项选择:
1、
An alternate method of installing the NVIDIA driver was detected.(This is usually a package provided by your distributor.) A driver installed via that method may integrate better with you system than a driver installed by
naidia-installer.
Please review the message provided by the maintainer of this alternate installation method and decide how to proceed:
Continue installation Abort installtion
The NVIDIA driver provided by Ubuntu can be installed by launching the "Software & Updates" application,and by selecting the NVIDIA driver from the "Additional Drivers" tab.
选择"Continue installation"
2、
Install NVIDIA's 32-bit compatibility libraries?
选择"No"
3、
Would you like to run the nvidia-xconfig utility to automatically update you X configuration file so that the NVIDIA X driver will be used when you restart X? Any pre-existing X configuration file will be backed up.
选择"Yes"
4、
Your X configuration file has been successfully updated. Installation of the NVIDIA Accelerated Graphics Driver for Linux-x86_64 (version:535.113.01) is now complete.
说明安装驱动成功。
安装完毕打开图形界面并且重启电脑
注:重启后进入bios设置,确认:1.设置独显直连 2.关闭安全启动
sudo service lightdm start && reboot
重启后检查是否安装成功
终端输入以下命令
nvidia-smi
显示如下:
Thu Oct 12 11:19:09 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.113.01 Driver Version: 535.113.01 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| 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 RTX 3050 ... Off | 00000000:01:00.0 On | N/A |
| N/A 33C P8 6W / 60W | 70MiB / 4096MiB | 3% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 945 G /usr/lib/xorg/Xorg 65MiB |
+---------------------------------------------------------------------------------------+
方法2:驱动和CUDA同时安装
文件下载
网址:https://developer.nvidia.com/cuda-toolkit-archive 依次点击
(1)"CUDA Toolkit 11.6.2"
(2)"Linux"
(3)"x86_64"
(4)"Ubuntu"
(5)"20.04"
(6)"runfile(local)"
在"Installation Instructions:"下方为下载安装指令
下载指令(文件需下载到英文路径),如:
cd /home/heqingchun/soft/nvidia
在"/home/heqingchun/soft/nvidia"路径中下载得到"cuda_11.6.2_510.47.03_linux.run"文件 以下是安装时使用的指令
sudo sh cuda_11.6.2_510.47.03_linux.run
安装驱动前的系统配置工作
(1)卸载原有驱动
sudo apt remove --purge nvidia*
禁用nouveau
备份文件
sudo cp /etc/modprobe.d/blacklist.conf /etc/modprobe.d/blacklist.conf.backup
打开文件
sudo gedit /etc/modprobe.d/blacklist.conf
修改文件
在文件末尾添加如下内容
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
保存后关闭文件
关闭nouveau
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
更新
sudo update-initramfs -u
重启电脑
reboot
重启后查看是否禁用成功
执行以下内容,没有任何输出内容则为成功禁用
lsmod | grep nouveau
开始安装驱动与cuda(以下需要进入黑窗口,可以将下面命令拍照或使用手机CSDN查看继续)
(1)按下组合键ctrl+alt+f3(f1-f6均可)进入字符界面
(2)字符界面登陆
注意此时小键盘不可用,先输入用户名,在输入密码
(3)关闭图形界面
sudo service lightdm stop
赋予可执行权限
chmod 755 cuda_11.6.2_510.47.03_linux.run
运行安装
sudo sh cuda_11.6.2_510.47.03_linux.run
期间会弹出对话框,需手动输入"accept"回车
CUDA Installer │
│ - [X ] Driver │
│ [X ] 510.47.03 │
│ + [X] CUDA Toolkit 11.6 │
│ [X] CUDA Samples 11.6 │
│ [X] CUDA Demo Suite 11.6 │
│ [X] CUDA Documentation 11.6 │
│ Options │
│ Install
向下选择"install"后等待安装完毕即可。
(6)安装完毕打开图形界面并且重启电脑
注:重启后进入bios设置,确认:1.设置独显直连 2.关闭安全启动
sudo service lightdm start && reboot
重启后检查是否安装成功
终端输入以下命令
nvidia-smi
显示如下:
Thu Oct 12 11:19:09 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.113.01 Driver Version: 535.113.01 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| 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 RTX 3050 ... Off | 00000000:01:00.0 On | N/A |
| N/A 33C P8 6W / 60W | 70MiB / 4096MiB | 3% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 945 G /usr/lib/xorg/Xorg 65MiB |
+---------------------------------------------------------------------------------------+