I just had a similar problem on 22.04 LTS.
Purging some old linux kernels somehow broke something and any attempt to install any package resulted in an attempt to build the nvidia dkms bits and failing horribly.
Rebooting landed me without any nvidia support, with fallback VGA drivers.
My fix was to:
- reboot (and ssh from another box to continue, before 800x600 just isn’t enough pixels.)
- remove all nvidia drivers ( I had 515, 525 and 535 laying around, for whatever reason.)
- visit /var/lib/dkms. notice there’s a lingering nvidia folder there, with a version subfolder (which happens to be missing a symlink to a related sources folder.)
- wipe /var/lib/dkms/nvidia folder entirely.
- install nvidia driver again (I used
sudo ubuntu-drivers install
, butsudo apt install nvidia-driver-535
or some such should work too.) - marvel as the installation succeeds without errors.
I became aware of the /var/lib/dkms/nvidia folder by looking for relevant log files. I had something interesting under /var/crash/nvidia-dkms-535.0.crash
, which mentioned Consult /var/lib/dkms/nvidia/535.113.01/build/make.log for more information.
I’m going to forget all of this now, but maybe this will help someone else down the line.