Reinstalling NVIDIA drivers on Zorin OS

I've run into this issue twice now while using Zorin OS so it made sense to leave notes on resolving them as well as links to resources. The root issue appears to be instability with driver updates. Given that my use case is primarily machine learning, having a driver update render a machine unusable is a major setback.

Many of the instructions I've seen online suggest using the graphics-drivers PPA, however, faulty updates end up getting shipped there before testing so I'd advise pulling from there with caution and freezing updates if you find something that works until you have a need to update (see: https://forums.linuxmint.com/viewtopic.php?t=431349)

If you have the PPA installed, this is the command to remove it

sudo add-apt-repository --remove ppa:graphics-drivers/ppa

This is a script I put together that automates the re-installation process. It might not be the best or most researched but it is what worked for me

set -e

VERSION=550

# https://forum.zorin.com/t/how-to-reinstall-nvidia-graphics-driver/21283
sudo apt purge 'nvidia-*' -y
sudo apt autoremove
sudo apt autoclean

# remove leftover driver files
# https://forums.developer.nvidia.com/t/errors-were-encountered-while-processing-dkms/236521/14
sudo rm -rf /var/lib/dkms/nvidia/
sudo dpkg --purge $(dpkg -l | grep nvidia | awk '{print $2}') || true

# https://github.com/oddmario/NVIDIA-Ubuntu-Driver-Guide
sudo apt update && sudo apt upgrade -y
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 
sudo apt install linux-headers-$(uname -r)
sudo apt install nvidia-driver-$VERSION -y

# Prevent updates to this package
# https://www.techrepublic.com/article/linux-101-how-to-hold-packages-back-from-getting-upgraded-with-apt/
sudo apt-mark hold nvidia-driver-$VERSION
sudo reboot

set +e

Subscribe to Another Dev's Two Cents

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe