Error while installing CUDA 12.1 on ubuntu 22.04

After almost 3-4 days of struggle I’m finally creating a topic regarding this.
Background: I’m on Kubuntu 22.04, and wanted to work on pytorch-cuda 12.1. So I wanted to install cuda 12.1. I checked out the CUDA 12.1 Toolkit download page, followed the instruction, everything was fine during installation then I got this error.

update-initramfs: Generating /boot/initrd.img-6.5.0-35-generic
I: The initramfs will attempt to resume from /dev/sda3
I: (UUID=14fb6d4d-e4db-45a5-b4de-579c527f9d63)
I: Set the RESUME variable to override this.
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for libc-bin (2.35-0ubuntu3.7) ...
Processing triggers for man-db (2.10.2-1) ...
Errors were encountered while processing:
 nvidia-dkms-530
 cuda-drivers-530
 nvidia-driver-530
 cuda-drivers
 cuda-runtime-12-1
 cuda-12-1
 cuda
 cuda-demo-suite-12-1
E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried overwriting as mentioned in this post https://askubuntu.com/a/1116795

I tried again, and got this error:

NFO:Enable nvidia
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
Removing old nvidia-530.30.02 DKMS files...
Deleting module nvidia-530.30.02 completely from the DKMS tree.
Loading new nvidia-530.30.02 DKMS files...
Building for 6.5.0-35-generic
Building for architecture x86_64
Building initial module for 6.5.0-35-generic
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/nvidia-dkms-530.0.crash'
Error! Bad return status for module build on kernel: 6.5.0-35-generic (x86_64)
Consult /var/lib/dkms/nvidia/530.30.02/build/make.log for more information.
dpkg: error processing package nvidia-dkms-530 (--configure):
 installed nvidia-dkms-530 package post-installation script subprocess returned error exit status 10
dpkg: dependency problems prevent configuration of cuda-drivers-530:
 cuda-drivers-530 depends on nvidia-dkms-530 (>= 530.30.02); however:
  Package nvidia-dkms-530 is not configured yet.

dpkg: error processing package cuda-drivers-530 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of nvidia-driver-530:
 nvidia-driver-530 depends on nvidia-dkms-530 (= 530.30.02-0ubuntu1); however:
  Package nvidia-dkms-530 is not configured yet.

dpkg: error processing package nvidia-driver-530 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of cuda-drivers:
 cuda-drivers depends on cuda-drivers-530 (= 530.30.02-1); however:
  Package cuda-drivers-530 is not configured yet.

dpkg: error processing package cuda-drivers (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of cuda-runtime-12-1:
 cuda-runtime-12-1 depends on cuda-drivers (>No apport report written because the error message indicates its a followup error from a previous failure.
                                              No apport report written because the error message indicates its a followup error from a previous failure.
                                               No apport report written because MaxReports is reached already
    No apport report written because MaxReports is reached already
                                                                  No apport report written because MaxReports is reached already
                       = 530.30.02); however:
  Package cuda-drivers is not configured yet.

dpkg: error processing package cuda-runtime-12-1 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of cuda-12-1:
 cuda-12-1 depends on cuda-runtime-12-1 (>= 12.1.0); however:
  Package cuda-runtime-12-1 is not configured yet.

dpkg: error processing package cuda-12-1 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of cuda:
 cuda depends on cuda-12-1 (>= 12.1.0); however:
  Package cuda-12-1 is not configured yet.

dpkg: error processing package cuda (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of cuda-demo-suite-12-1:
 cuda-demo-suite-12-1 depends on cuda-runtime-12-1; however:
  Package cuda-runtime-12-1 is not configured yet.

dpkg: error processing package cuda-demo-suite-12-1 (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              No apport report written because MaxReports is reached already
                   Processing triggers for initramfs-tools (0.140ubuntu13.4) ...
update-initramfs: Generating /boot/initrd.img-6.5.0-35-generic
Errors were encountered while processing:
 nvidia-dkms-530
 cuda-drivers-530
 nvidia-driver-530
 cuda-drivers
 cuda-runtime-12-1
 cuda-12-1
 cuda
 cuda-demo-suite-12-1
E: Sub-process /usr/bin/dpkg returned an error code (1)

As I already made a timeshift stamp while booting into new Kubuntu 22.04. So I rolled back and tried again and got same error. I tried disabling secure boot but still got the same error.
I wasted around 3-4 days figuring this out but couldn’t solved it. I need help regarding this issue.