Installing Nvidia Drivers on Ubuntu - The Easy Way

I had installed Nvidia Drivers on my Desktop using ubuntu-drivers --autoinstall thinking that everything should work properly. But turns out I was wrong. It had weird issues, and I was not able to use the Nvidia Encoder in OBS either. So, this is what I had to do to get everything fixed.

Step 1 - Remove any old drivers

Step 1.1 If they were installed through the PPA

That is, if you installed the drivers using apt

sudo apt-get remove --purge '^nvidia-.*'
sudo apt autoremove
reboot

Move on to step 2

Step 1.2 If they were installed through Nvidia installer script

If for some reason you used the .run file from Nvidia website, follow this

💡
Unfortunately, the Nvidia driver installer scripts are notoriously bad (at least in my experience) for Linux. It is best to stick with the PPA method

First, remove any potential Nouveau (the open source driver) blacklists that was created by Nvidia installer

sudo rm -rf /lib/modprobe.d/nvidia-installer-*
sudo rm -rf /etc/modprobe.d/nvidia-installer-*
sudo rm -rf /usr/lib/modprobe.d/nvidia-installer-*

VERY IMPORTANT!!

💡
Please read this carefully or you could end up with blank screen on boot

Check your /etc/default/grub file and look for any entries such as nvidia-drm.modeset, nvidia-drm.fbdev

Update grub

sudo update-grub

Download the installer from Nvidia website and run it

sudo nvidia-installer --uninstall

rebuild initramfs

sudo update-initramfs -u

Step 2 - Install the Dependencies

sudo apt install pkg-config libglvnd-dev dkms build-essential libegl-dev libegl1 libgl-dev libgl1 libgles-dev libgles1 libglvnd-core-dev libglx-dev libopengl-dev gcc make 

Step 3 - Find the latest Nvidia Driver version

Go HERE and find the latest driver version, you will see something like this.

So, in my case, 575 is the latest version

Step 4 - Install the Driver

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update 
sudo apt install nvidia-driver-575
reboot

Step 5 - Verify

Run nvidia-smi and see that everything is installed properly. You should see something like this

Kani

NYC