本博客所有的安装包在百度盘,大家自取:
链接: https://pan.baidu.com/s/1NkgOnaLzmBQ_rW4hbqdnqg 密码: q3sn
--来自百度网盘超级会员V4的分享
在命令行中输入
sudo apt-get remove cuda
sudo apt --purge remove "*cublas*" "cuda*"
sudo apt-get autoclean
sudo apt-get remove cuda*
sudo apt-get remove --purge nvidia*
然后在目录切换到/usr/local/下
cd /usr/local/
sudo rm -r cuda-9.1
使用标准Ubuntu仓库进行自动化安装
使用PPA仓库进行自动化安装
使用官方的NVIDIA驱动进行手动安装
上述三种方法均可用,我个人更习惯于使用手动安装。
注意:
在安装之前首先就是要禁用Nouveau的驱动,禁用该驱动的方法参照这篇博客。
上一步的改动只是在安装的时候临时禁用。如果没有永久禁用该驱动,可能会出现安装完毕NIVIDA显卡后无法进入Ubuntu的情况(在登录界面,输入密码也无法登录)。
所以,在安装后Ubuntu成功后需要在grub的配置文件里面更改:
sudo gedit /boot/grub/grub.cfg
在文本中搜索quiet splash 然后添加acpi_osi=linux nomodeset,保存文本即可。
这种方法几乎是所有的示例中最简单的方法,也是该教程最为推荐的方法。首先,检测你的NVIDIA显卡型号和推荐的驱动程序的模型。在命令行中输入如下命令:
ubuntu-drivers devices
得到如下输出
== /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0 ==
modalias : pci:v000010DEd00002206sv00001458sd0000403Fbc03sc00i00
vendor : NVIDIA Corporation
driver : nvidia-driver-460-server - distro non-free
driver : nvidia-driver-465 - distro non-free recommended
driver : nvidia-driver-460 - distro non-free
driver : nvidia-driver-455 - third-party free
driver : xserver-xorg-video-nouveau - distro free builtin
从输出结果可以看到建议安装驱动程序是 nvidia-driver-465版本的驱动。如果您同意该建议,请再次使用Ubuntu驱动程序命令来安装所有推荐的驱动程序。
输入以下命令:
sudo ubuntu-drivers autoinstall
一旦安装结束,重新启动系统,你就完成了。
使用图形驱动程序PPA存储库允许我们安装NVIDIA beta驱动程序,但是这种方法存在不稳定的风险。
首先,将ppa:graphics-drivers/ppa存储库添加到系统中:
sudo add-apt-repository ppa:graphics-drivers/ppa
为了防止无法添加ppa,执行以下命令:
sudo bash
export https_proxy=http://[username:password@]www.proxy.com:8000/
exit
然后执行:
sudo apt update
如果出现以下错误(ubuntu apt-get update 提示签名无效):
W: GPG error: http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FCAE110B1118213C
E: The repository 'http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
执行以下操作:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FCAE110B1118213C
sudo apt-key adv --keyserver hkp://pool.sks-keyservers.net:80 --recv-keys FCAE110B1118213C
gpg -a --export FCAE110B1118213C | sudo apt-key add
sudo apt-get clean
cd /var/lib/apt
sudo mv lists lists.old
sudo mkdir -p lists/partial
sudo apt-get clean
sudo apt-get update
接下来,识别显卡模型和推荐的驱动程序:
ubuntu-drivers devices
得到以下输出
== /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0 ==
modalias : pci:v000010DEd00002206sv00001458sd0000403Fbc03sc00i00
vendor : NVIDIA Corporation
driver : nvidia-driver-455 - third-party free
driver : nvidia-driver-465 - distro non-free recommended
driver : nvidia-driver-460 - distro non-free
driver : nvidia-driver-460-server - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
输入以下命令:
sudo apt install nvidia-driver-465
如果报以下错误:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
nvidia-driver-465 : Depends: libnvidia-gl-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: libnvidia-compute-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: libnvidia-extra-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: nvidia-compute-utils-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: libnvidia-decode-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: libnvidia-encode-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: nvidia-utils-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: xserver-xorg-video-nvidia-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: libnvidia-ifr1-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Depends: libnvidia-fbc1-465 (= 465.27-0ubuntu0.18.04.2) but it is not going to be installed
Recommends: libnvidia-compute-465:i386 (= 465.27-0ubuntu0.18.04.2)
Recommends: libnvidia-decode-465:i386 (= 465.27-0ubuntu0.18.04.2)
Recommends: libnvidia-encode-465:i386 (= 465.27-0ubuntu0.18.04.2)
Recommends: libnvidia-ifr1-465:i386 (= 465.27-0ubuntu0.18.04.2)
Recommends: libnvidia-fbc1-465:i386 (= 465.27-0ubuntu0.18.04.2)
Recommends: libnvidia-gl-465:i386 (= 465.27-0ubuntu0.18.04.2)
E: Unable to correct problems, you have held broken packages.
则执行:
sudo apt-get install aptitude
然后执行:
sudo aptitude install nvidia-driver-465
一旦完成,即可重新启动系统。
这种方式也是我最常用的方式,安装方式如下。
首先识别NVIDIA显卡型号,输入一下命令:
lshw -numeric -C display
或者
lspci -vnn | grep VGA
下载NVIDIA官方显卡驱动,然后存储到相应路径。
停止可视化桌面:
sudo telinit 3
之后会进入一个新的命令行会话,使用当前的用户名密码登录
在相应路径下安装NVIDIA驱动(安装文件也可为.sh后缀,如果提示没有权限使用sudo):
bash NVIDIA-Linux-x86_64-xxx.bin
按照以下步骤:
Accept License
The distribution-provided pre-install script failed! Are you sure you want to continue? -> CONTINUE INSTALLATION
Would you like to run the nvidia-xconfig utility? -> YES
在安装结束后,在命令行输入一下命令重启,NVIDIA驱动即可安装成功:
sudo reboot
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda-repo-ubuntu1804-11-1- local_11.1.0-455.23.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-11-1-local_11.1.0-455.23.05-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu1804-11-1-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
sudo vim ~/.bashrc
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc
执行:
nvcc -V
进入:
https://developer.nvidia.com/rdp/cudnn-download
下载“cuDNN Library for Linux”,下载完成后解压tgz文件,得到一个cuda文件夹:
tar -xzvf cudnn-11.1-linux-x64-v8.0.4.30.tgz
然后复制文件:
sudo cp cuda/include/cudnn.h /usr/local/cuda-11.1/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.1/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2