I had the same problem on Ubuntu 24.x LTS while trying to install NVIDIA 550 drivers and couldn’t fix it somehow.
I was getting the error below all the time when trying to purge and autoremove:
Setting up nvidia-dkms-545 (545.29.06-0ubuntuo~gpuz4.04.1) ... update-initramfs: deferring update (trigger activated)
INFO: Enable nvidia
DEBUG: Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put-your_quirks_here
DEBUG: Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
Removing old nvidia-545.29.06 DKMS files...
Deleting module nvidia-545.29.06 completely from the DKMS tree.
Loading new nvidia-545.29.06 DKMS files...
Building for 6.8.0-31-generic
Building for architecture x86_64
Building initial module for 6.8.0-31-generic
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/nvidia-kernel-source-545.0.crash'
Error! Bad return status for module build on kernel: 6.8.0-31-generic (x86_64)
Consult /var/lib/dkms/nvidia/545.29.06/build/make. log for more information. dpkg: error processing package nvidia-dkms-545 (--configure):
installed nvidia-dkms-545 package post-installation script subprocess returned error exit status 10• opkg: dependency problems prevent configuration of nvidia-driver-545: nvidia-driver-545 depends on nvidia-dkms-545 (<= 545.29.06-11; however:
Package nvidia-dkms-545 is not configured yet. nvidia-driver-545 depends on nvidia-dkms-545 (>= 545.29.06); however:
Package nvidia-dkms-545 is not configured yet. dpkg: error processing package nvidia-driver-545 (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Processing trigge
update-initramfs: Generating /boot/initrd, img-6,8,0-31-generic
Errors were encountered while processing:
nvidia-dkms-545
E: Sub-process /us/bin/dpkg returned an error code (1)
So steps I have followed are like these:
- First of all, I wiped “/var/lib/dkms/nvidia” folder just like @Metalbot indicated in his post.
And then,
- Purged anything related to nvidia drivers:
sudo apt-get purge 'nvidia-*'
sudo apt-get autoremove
sudo apt-get autoclean
- Removed residual configuration files
sudo dpkg --purge $(dpkg -l | grep nvidia | awk '{print $2}')
There were bunch of leftovers from old drivers, like 510/535/545. So I got rid of them by the codes above.
- Installed/Re-Installed build-essential and other dependencies
sudo apt-get install build-essential dkms
sudo apt-get install linux-headers-$(uname -r)
- Installed the drivers I’ve been trying to
sudo apt-get install nvidia-driver-550
- Rebuilt the initramfs image
sudo update-initramfs -u
- And rebooted
sudo reboot
and I got it working without any problems afterwards.
Edit:
I’ve done all of that in recovery mode of Ubuntu, from shell with no graphical interface to avoid any gpu usage by nvidia drivers.