Error with NVIDIA drivers + Linux 6.5 on elementary OS 7 / Ubuntu 22.04

Recently, Ubuntu Hardware Enablement Stack updated the kernel to 6.5, which broke a bunch of DKMS drivers, one of them being the NVIDIA ones. In my case, the error was caused by a mismatch between the gcc installed by default (GCC 11), and the one required for building on this kernel (GCC 12). I solved it like this:

sudo apt install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 20

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 20

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

I then reconfigured the dkms package (nvidia-dkms-535) by running sudo dpkg-reconfigure nvidia-dkms-535 and restarted to get it working again. Documenting it here for posterity.

Published by

Leave a comment