# 安装
sudo apt install python3-pip
# 升级
sudo pip3 install --upgrade pip
# 如果要卸载,使用命令:
sudo apt-get remove python3-pip
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
2、添加两行语句:
blacklist nouveau
options nouveau modeset=0
3、更新initramfs
sudo update-initramfs -u
4、重启
reboot
5、验证,终端输入语句,
lsmod | grep nouveau
# 没有输出说明操作成功
cat /proc/driver/nvidia/version
# 查找可选择安装的版本自动安装
sudo ubuntu-drivers autoinstall
# 列出设备,显示的model是显卡型号,driver是可选的驱动
ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00002504sv00001458sd00004072bc03sc00i00
vendor : NVIDIA Corporation
model : GA106 [GeForce RTX 3060 Lite Hash Rate]
manual_install: True
driver : nvidia-driver-470-server - distro non-free
driver : nvidia-driver-515-server - distro non-free
driver : nvidia-driver-510-server - distro non-free
driver : nvidia-driver-470 - distro non-free
driver : nvidia-driver-510 - distro non-free
driver : nvidia-driver-520 - distro non-free
driver : nvidia-driver-515-open - distro non-free
driver : nvidia-driver-520-open - distro non-free recommended
driver : nvidia-driver-515 - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
# 安装其中 recommended 一个驱动
sudo apt install nvidia-driver-520-open
sudo reboot
如果出现 : Failed to initialize NVML: Driver/library version mismatch
,则可能是版本不对。
我这很不幸地出现 : no devices were found
,最后使用下面方式安装成功。
https://www.nvidia.com/Download/index.aspx?lang=en-us
# 查看显卡型号
lspci -vnn | grep VGA
# 卸载旧驱动
sudo apt-get remove --purge nvidia*
# 给run文件可执行权限
sudo chmod a+x NVIDIA-Linux-x86_64-515.86.01.run
# 安装
sudo ./NVIDIA-Linux-x86_64-440.64.run -no-x-check -no-nouveau-check -no-opengl-files
# -no-x-check:安装驱动时关闭X服务
# -no-nouveau-check:安装驱动时禁用nouveau
# -no-opengl-files:只安装驱动文件,不安装OpenGL文件
提示: Would you like to register the kernel module sources with DKMS?
选择No
提示: Nvidia's 32-bit compatibility libraries?
选择No
提示: Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x?
选择Yes
安装完重新启动电脑。
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu
我这里下载的是Cuda11.8:
需要注意的是,之前已经安装过显卡驱动程序,在提问是否安装显卡驱动时选择no
其他 选择默认路径或者yes即可。
sudo /usr/local/cuda-11.8/bin/uninstall_cuda_8.0.pl
sudo rm -rf /usr/local/cuda-8.0
chomd +x cuda_11.8.0_520.61.05_linux.run
sudo ./cuda_11.8.0_520.61.05_linux.run
https://developer.nvidia.com/rdp/cudnn-download
这里下载 deb 格式,安装:
sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.0_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2204-8.6.0.163/cudnn-local-FAED14DD-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get install libcudnn8=8.6.0.163-1+cuda11.8 # 这里输入到=按tab补全即可,安装运行库
sudo apt-get install libcudnn8-dev=8.6.0.163-1+cuda11.8 # 通过tab自动补全,安装developer 库
sudo apt-get install libcudnn8-samples=8.6.0.163-1+cuda11.8 # 通过tab自动补全,安装示例和文档
cp -r /usr/src/cudnn_samples_v8/ $HOME
cd ~/cudnn_samples_v8/mnistCUDNN/
make clean && make
# 如果提示下面截图中的错误,就执行下面语句安装freeimage3库
sudo apt-get install libfreeimage3 libfreeimage-dev
运行测试:
./mnistCUDNN