Cannot install 440.82 driver on Ubuntu 20.04 LTS (focal)

I’ve been using the 440.82 driver without problems on Ubuntu 20.04 LTS (focal) on a NVS 510 multi-monitor system for about 2 weeks, until I ran a “sudo apt-get update && sudo apt-get upgrade” – and then Gnome showed errors (crashed) after login, so I tried to rebuild the driver with ./, as is often necessary. after an upgrade, but this time the build failed with the following error message:

ERROR: Failed to run `/usr/sbin/dkms build -m nvidia -v 440.82 -k 5.3.0-40-generic`: Error! Your kernel headers for kernel 5.3.0-40-generic cannot be found.
             Please install the linux-headers-5.3.0-40-generic package,
             or use the --kernelsourcedir option to tell DKMS where it's located

The “linux-headers-5.3.0-40-generic” package is not available for Ubuntu 20.04 LTS (focal), as much newer files are already installed (“linux-headers-5.4.0-37-generic”):

 sudo  apt list --installed | grep linux-headers

    WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

    linux-headers-5.4.0-37-generic/focal-updates,focal-security,now 5.4.0-37.41 amd64 [installed,automatic]
    linux-headers-5.4.0-37/focal-updates,focal-updates,focal-security,focal-security,now 5.4.0-37.41 all [installed,automatic]
    linux-headers-generic/focal-updates,focal-security,now amd64 [installed,automatic] 

FWIW, I tried to load “linux-headers-5.3.0-40-generic” from 18.04 (bionic), which required to ignore compiler warnings (because that package was compiled with gcc 7.3 while current version is 9.3).

I don’t know if the most recent 20.04 LTS upgrade had files removed, but I think the nVidia driver needs to be updated to reflect the current packages.

I did some more digging on this issue over the weekend and, after I found remnants of the 19.10 release I had used before I did the apt dist-upgrade to 20.04 and 20.04 LTS (specifically, among them was a 5.3.0-40-generic Linuz boot files, etc), I chose to re-format the hard disk and reinstalled 20.04 LTS from scratch (which required to use ‘Safe graphics’ mode when booting from the USB installer).

After the fresh 20.04 LTS install, trying to install the 440.82 driver warned me that there was already a nVidia driver supplied by the distro (but the installer did not mention the version). Therefore I opted to abort the install, using the distro driver (which happens to be 440.64, according to the ‘nVidia X Server’ app) and see what happens down the road.

So, in a nutshell, it appears as if the sudo apt-get update && sudo apt-get upgrade I had done on the 20.04 LTS system somehow corrupted and confused that system by referring back to some 19.10 file residue – which, among other problems, then also made the 440.82 driver installation fail.

For now, the problem is solved.