Skip to content

Instantly share code, notes, and snippets.

@trungnt13
Last active March 29, 2023 21:43
Show Gist options
  • Save trungnt13/37024ef5c3fbabfb8fb2dbc64df7d9aa to your computer and use it in GitHub Desktop.
Save trungnt13/37024ef5c3fbabfb8fb2dbc64df7d9aa to your computer and use it in GitHub Desktop.
# Open a putty-terminal with Ctrl + Alt + F1
######## Download the driver
# for GTX 960 (Aug 22, 2016)
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/367.35/NVIDIA-Linux-x86_64-367.35.run
######## Preparing
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo apt-get install build-essential && sudo apt-get install linux-source && sudo apt-get install linux-headers-generic
sudo nano /etc/default/grub #change line "GRUB_CMDLINE_LINUX_DEFAULT..."-line to
GRUB_CMDLINE_LINUX_DEFAULT="nouveau.blacklist=1 quiet splash nomodeset" #(forces low-level graphics to ensure putty does not give black screen)
sudo update-grub2
sudo apt-get remove nvidia* && sudo apt-get autoremove #ensures no former installation clashes with new install
sudo reboot
######## After reboot get correct nvidia-driver (chose graphic-card and OS) at “http://www.nvidia.com/Download/index.aspx?lang=en-us" (or search webb with “nvidia download”). Right-click on downloaded file and change if to executable.
sudo nano /etc/modprobe.d/blacklist.conf #add these lines at the end:
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
# Open a putty-terminal with Ctrl + Alt + F1
sudo service lightdm stop #stops graphic session to enable nvidiainstallation
cd Downloads #(or wherever you downloaded your nvidia-file)
sudo ./{the downloadedfilename.run} #follow installation-instructions (normally yes to all)
sudo nvidia-xconfig #(if you did not chose “yes” to this in the installation”
sudo nano /etc/default/grub # change the "GRUB_CMBLINE_LINUX_DEFAULT..."-line to below:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset”
sudo update-grub2 #update grub!
sudo reboot
# Original thread: https://ubuntuforums.org/showthread.php?t=2263316
sudo apt install -y linux-headers-$(uname -r)
sudo systemctl restart gdm3
sudo init 3 && sudo systemctl stop gdm3
sudo init 5 && sudo systemctl start gdm3
@trungnt13
Copy link
Author

trungnt13 commented Jan 6, 2022

sudo apt-get remove --purge '^nvidia-.*'
sudo apt-get remove --purge '^libnvidia-.*'
sudo apt-get remove --purge '^cuda-.*'
sudo apt-get remove --purge "*nvidia*"

sudo apt-get install linux-headers-$(uname -r)

@trungnt13
Copy link
Author

trungnt13 commented Mar 23, 2022

Remove CUDA toolkit

sudo apt-get --purge remove "*cublas*" "cuda*" "nsight*" 
sudo rm -rf /usr/local/cuda*

# To uninstall cuda
sudo /usr/local/cuda-11.4/bin/cuda-uninstaller 
# To uninstall nvidia
sudo /usr/bin/nvidia-uninstall

sudo apt-get autoremove
sudo apt-get autoclean

If installed driver from NVIDIA run

sudo ./NVIDIA-Linux-x86-310.19.run --uninstall

@trungnt13
Copy link
Author

Find all installed CUDA

find / -type d -name cuda 2>/dev/null

@trungnt13
Copy link
Author

trungnt13 commented Mar 23, 2022

Install NVIDIA Drivers – NVIDIA Repo

import GPG key
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub

add repo
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"

pin file
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600

update apt-cache
sudo apt update

without CUDA
sudo apt install libglvnd-dev pkg-config dkms build-essential nvidia-driver-510 nvidia-settings nvidia-utils-510 linux-headers-$(uname -r) -y

with CUDA
sudo apt install libglvnd-dev pkg-config dkms build-essential cuda nvidia-driver-510 nvidia-settings nvidia-utils-510 linux-headers-$(uname -r)


Install NVIDIA Drivers – PPA Repo

sudo add-apt-repository ppa:graphics-drivers/ppa -y
ubuntu-drivers devices
sudo apt update
sudo apt install nvidia-driver-510 -y

@trungnt13
Copy link
Author

Update Nvidia driver

apt-cache search 'nvidia-driver-' | grep '^nvidia-driver-[[:digit:]]*'
## search for DKMS package too ##
apt-cache search 'nvidia-dkms-' | grep '^nvidia-dkms-[[:digit:]]*'

sudo apt update
sudo apt upgrade

sudo apt install nvidia-driver-510 nvidia-dkms-510

sudo reboot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment