Just recently, I have tried to update my graphics drivers from version 535.146.02 to 535.154.05 and while the uninstallation of the old driver was successful, the installation of the new one is not. Attempted installation of the old driver also resulted in failure with the same error.
I have tried purging all Nvidia packages from my system, looking for Nvidia files and deleting them by hand, and even running apt-upgrade but, still no success.
That’s an issue with the Ubuntu kernel. For whatever reasons, the ubuntu kernel team decided to use gcc-12 for kernel compilation while the 22.04 system compiler is gcc-11. Please install gcc-12 from ubuntu repo to be able to compile the nvidia modules again.
That’s strange though. I’ve tried installing older drivers down to the one that I’ve first installed on August 2022 when I built my computer and they all failed. Funny enough, I’ve only had up to GCC 11 in my system and all drivers installed with no problems until today.
Problem solved though. I installed GCC 12 and driver 535.154.05 is now installed successfully. Much thanks.