1.換源
裝完系統后,首先進行換源。我一般使用阿里雲的源,也可以使用其他的國內源
①備份Ubuntu原始的源
sudo cp /etc/apt/sources.list /etc/apt/sources_init.list
②修改源文件
sudo gedit /etc/apt/sources.list
③將下列內容復制進去
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
④更新源
sudo apt-get update
也可修復損壞的軟件包(可跳過此步驟)
sudo apt-get -f install
sudo apt-get upgrade
2.安裝NVIDIA驅動
注意:安裝驅動之前,先進入BOIS中關掉Secure boot。
①安裝依賴項
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
②去NVIDIA官網選擇適合自己電腦的顯卡驅動
https://www.nvidia.com/Download/index.aspx?lang=en-us%EF%BC%8C%E6%9F%A5%E7%9C%8B%E9%80%82%E5%90%88%E8%87%AA%E5%B7%B1%E6%98%BE%E5%8D%A1%E7%9A%84%E9%A9%B1%E5%8A%A8%E5%B9%B6%E4%B8%8B%E8%BD%BD%EF%BC%9A

下載的文件是.run結尾的(最好不要在路徑中出現中文)
③在終端輸入
sudo gedit /etc/modprobe.d/blacklist.conf
禁用Ubuntu自帶的驅動
blacklist nouveau
options nouveau modeset=0
④然后再次輸入下面命令,用來更新系統內核
sudo update-initramfs -u
⑤更新完需要重啟電腦
sudo reboot
⑥重啟完電腦后,需要驗證是否禁用成功(如果沒有任何輸出,則說明禁用成功)
lsmod | grep nouveau
⑦進入文本模式下進行安裝nvidia
按快捷鍵ctrl+alt+F4(F1-F7都可以),然后輸入自己的用戶名和密碼。
輸入下面命令,確保自己電腦沒有裝任何驅動
sudo apt-get remove –purge *nvidia*
然后關掉圖形化界面
sudo service lightdm stop
用cd進入到下載.run文件的文件夾下面,如果默認路徑則是/home/用戶名/Download/xxx.run。然后賦予權限(我一般都習慣性的賦予最高權限)
sudo chmod 777 NVIDIA-Linux-x86_64-470.74.run
⑧安裝.run
sudo sh ./NVIDIA-Linux-x86_64-470.74.run
⑨重啟電腦,並輸入
nvidia-smi

如果顯示上面這樣的,就證明安裝成功了。
3.問題匯總
不過很多人重啟電腦后,發現進入不了圖形化界面。報錯“hdaudio:hdaudioC0D2 unable to bind the codec”
第一種解決方式,在Ubuntu啟動的時候進入高級選項,然后選擇recovery 模式。在root下面卸載nvidia驅動,然后重新安裝即可。
第二種解決方式,按住快捷鍵ctrl+alt+F4進入文本模式,修改grub文件
sudo vi /etc/default/grub
修改GRUB_CMDLINE_LINUX_DEFAULT,修改后為
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"
然后wq:保存並更新
sudo update-grub
