1. 将NVIDIA repository 加入你的 apt

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo apt update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt update

 2. 安装 NVIDIA Driver

ubuntu-drivers devices
sudo ubuntu-drivers autoinstall

期间我遇到了driver安装不完整的情况,所以重新再试一次:

sudo apt-get update --fix-missing
sudo ubuntu-drivers autoinstall

安装完以后重启开机:

sudo reboot

测试一下:

base) ➜  Frequent-use git:(master) nvidia-smi
Sun Aug 18 09:03:59 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.40 Driver Version: 430.40 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| 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 106... Off | 00000000:05:00.0 On | N/A |
| 29% 33C P8 8W / 120W | 110MiB / 6077MiB | 0% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1630 G /usr/lib/xorg/Xorg 39MiB |
| 0 2055 G /usr/bin/gnome-shell 68MiB |
+-----------------------------------------------------------------------------+

 这就安装上去了。

参考文献

[1].Ubuntu 18.04 安裝 NVIDIA Driver 418 & CUDA 10 & Miniconda & TensorFlow 1.13. ​​https://medium.com/@maniac.tw/ubuntu-18-04-%E5%AE%89%E8%A3%9D-nvidia-driver-418-cuda-10-tensorflow-1-13-a4f1c71dd8e5​